NodeJS API Client for abbasudo/laravel-purity
npm install purity-client-js
pnpm install purity-client-js
yarn add purity-client-jspublicfunctionindex(Request$request)
{
return Model::filter()->sort()->paginate($request->query('perPage'));
}import{PurityClient}from'purity-client-js';constapiClient=newPurityClient('http://localhost:8000/api')Pass page, perPage for default laravel paginate method
GET /api/articles?page=1&perPage=15
apiClient.get('articles',{page: 1,perPage: 15})Queries can accept a sort parameter that allows sorting on one or multiple fields with the following syntax's.
GET /api/articles?sort[0]=title&sort[1]=slug:desc
apiClient.get('articles',{sort: ['title','slug:desc']})All the usages of basic sorting are applicable. Use dot(.) notation to apply relationship in the following format.
GET /api/posts?sort=tags.name:asc
apiClient.get('articles',{sort: ['tags.name:asc']})Find users with 'John' as their first name
GET /api/users?filters[name][$eq]=JalalLinuX
apiClient.get('users',{filters: {username: {$eq: 'JalalLinuX'}}})Find multiple restaurants with ids 3, 6, 8
GET /api/restaurants?filters[id][$in][0]=3&filters[id][$in][1]=6&filters[id][$in][2]=8
apiClient.get('restaurants',{filters: {id: {$in: [3,6,8],},}})Find users with age between 20 and 30
GET /api/users?filters[age][$between][0]=20&filters[age][$between][1]=30
apiClient.get('users',{filters: {age: {$between: [20,30],},}})Complex filtering is combining multiple filters using advanced methods such as combining $and & $or. This allows for more flexibility to request exactly the data needed.
Find books with two possible dates and a specific author.
GET /api/books?filters[$or][0][date][$eq]=2020-01-01&filters[$or][1][date][$eq]=2020-01-02&filters[author][name][$eq]=Kai%20doe
apiClient.get('books',{filters: {$or: [{date: {$eq: '2020-01-01',},},{date: {$eq: '2020-01-02',},},],author: {name: {$eq: 'Kai doe',},},}})Relation filtering is filtering on a relation's fields.
Find restaurants owned by a chef who belongs to a 5-star restaurant
GET /api/restaurants?filters[chef][restaurants][stars][$eq]=5
apiClient.get('restaurants',{filters: {chef: {restaurants: {stars: {$eq: 5,},},},}})Complex relation filtering is combining multiple relation filters using advanced methods such as combining $and & $or. This allows for more flexibility to request exactly the data needed.
Find restaurants owned by a chef who belongs to a 5-star restaurant and has a specific cuisine
GET /api/restaurants?filters[chef][restaurants][stars][$eq]=5&filters[chef][restaurants][cuisine][$eq]=Italian
apiClient.get('restaurants',{filters: {chef: {restaurants: {stars: {$eq: 5,},cuisine: {$eq: 'Italian',},},},}})