laravel-rest-api-query-builder
JavaScript library to build RESTful API HTTP calls with Eloquent's-like syntax. This is made to work with RESTful APIs that use laravel-rest-api package.
This package is just a modification to milroyfraser/sarala in order to make it compatible with laravel-rest-api package.
All credits goes to milroyfraser.
Original package's documentation
Install
$ npm i laravel-rest-api-query-builder --save
$ yarn add laravel-rest-api-query-builder
Basic Usage
Model Implementation
app/models/BaseModel.js
; { return "https://myserver.com/api"; }
app/models/Post.js
;;;; { return 'posts'; } { return 'title' 'subtitle' 'body' 'slug'; } { // one of 'datetime', 'date' and 'time' return created_at: 'datetime' updated_at: 'datetime' ; } { return author: class: User list: false tags: class: Tag list: true comments: class: Comment list: true ; } { return { return postpublished_at; } { return postpublished_at; } ; }
app/models/Tag.js
;; { return 'tags'; } { return 'name'; } { return posts: class: Post list: true }
Fetching data
;; // Get the post with id 7Query ; // Get all postsQuery all ; // Get all posts with their author and tagsQuery all ; // Get, sort and limitQuery all ; // Paginate : 10 per page, 5th pageQuery ; // Get a post then get its authorQuery ;
Insert
app/components/MyComponent.js
; const tag = ;tagname = 'json-api'; // makes a POST request to https://sarala-demo.app/api/tagstag ; _saveconst tag2 = ;tag2name = 'tag2';tag2 ;