sedp-mis/base-api is a Laravel package for abstraction for api resources in laravel.
It currently has 0 GitHub stars and 99 downloads on Packagist (latest version v0.1.0).
Install it with composer require sedp-mis/base-api.
Discover more Laravel packages by sedp-mis
or browse all Laravel packages to compare alternatives.
Last updated
Abstraction for api resources in Laravel. Compatible to use with Laravel 4.2 and 5.*.
Use composer to install base-api and dependencies:
composer require sedp-mis/base-api
The purpose of this repository is to create an abstraction for common use-cases of api resources.
It is a good practice to version our api so we will set our base api to api/v1.
So in the following api implementations, the example resource to be used is posts.
METHOD | URL | Description
--- | --- | ---
GET | api/v1/posts | @index, List of resources
POST | api/v1/posts | @store, Create or store new resource
GET | api/v1/posts/{id} | @show, Show resource
PUT|PATCH | api/v1/posts/{id} | @update, Update resource
DELETE | api/v1/posts/{id} | @destroy, Destroy or delete resource
Notice that @<method> are the same with the controller methods in laravel.
GET methods like @index and @show.@index and @showattributes[]. Example:GET url?attributes[]=id&attributes[]=title
relations[]. Example:GET url?relations[]=comments&relations[]=labels
GET url?relations[comments][attributes][]=id&relations[comments][attributes][]=text
@indexGET url?page=1&per_page=100
This example shows that it is currently on the 1st page and showing 100 records per page.
Without page parameter, the list will default to all resources to be fetched.
filters[attribute][] parameter.GET url?filters[tag][]=cool&filters[tag][]=trending
equals operator (behaves like the default example):GET url?filters[tag][equals][]=cool&filters[tag][equals][]=trending
not_equals operator:GET url?filters[tag][not_equals][]=bug&filters[tag][not_equals][]=foo
search query parameter.GET url?search[input]=SomeTextToSearch&search[compare][]=title&search[compare][]=description
sort[attribute_1]=asc&sort[attribute_n]=desc. Example:GET url?sort[title]=asc