0.0.10 • Published 6 years ago

jquery-laravel-rest v0.0.10

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

jQuery RESTful callbacks on Laravel standard routes.

Lightweight jQuery plugin which allows you to communicate easily with your Laravel 5.4 server-side.

Install

Install the plugin via npm install jquery-laravel-rest. Then you just need to require('jquery-laravel-rest');.

Examples

Update a dataset via update-route on controller my-module:

$.rest('update', my_data_object, success: (data) => void)

Consider there is no id specified explicitly - it will automatically be attached to the route. The plugin expects you to have the id specified in my_data_object. The ID member can be specified as default value as we'll see later. Furthermore there is the base route required, i.e. when accessing a Laravel ResourceController for Users, then the url could be '~/users', for instance. The deeper parts (e.g. '/edit') will be added by the plugin.

The available REST-routes are: index, create, store, show, edit, update and destroy. The request URLs are set up as decribed in the Laravel-Docs (table).

Set a default value:

$.rest('default', { 'idField': 'my_id_member_on_each_object'});

The following default-values can be specified:

  • idField: The field name which holds the ID of each object (defaults to 'id').
  • url: The default url (maybe helpful when having requests only belonging to a specific module/controller; defaults to '~/').
  • csrf_token: Set the CSRF token Laravel expects most likely from you. Might be helpful to specify this within a script-tag in your header: <script> $.rest('csrf_token', {{ csrf_token(); }}); </script>. Alternatively you can configure the $.ajax with the csrf_token as X-CSRF-TOKEN as described here.
  • before_request: A callback function to call before each request. This callback takes no parameters and nothing is expected to be returned. It is not meant for preprocessing the data before request, but more for e.g. showing a loader.
  • after_request: As before_request, e.g. for hide the loader.

Hope this helps someone ;)

0.0.10

6 years ago

0.0.9

6 years ago

0.0.8

6 years ago

0.0.7

6 years ago

0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago