- Notifications
You must be signed in to change notification settings - Fork46
JSON:API for Laravel applications
License
laravel-json-api/laravel
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Implement feature-richJSON:API compliant APIs in yourLaravel applications. Build your next standards-compliant API today.
Great question!Here's some reasons from this excellent article by Denisa Halmaghi:
- Standardised, consistent APIs.
- Feature rich - some of which are: sparse fieldsets (only fetch the fields you need), filtering, sorting, pagination,eager loading for relationships (includes, which solve theN+1 problem).
- Easy to understand.
- Saves a lot of development time.
- Highly maintainable code.
- Great, extensive documentation.
- Strong conventions, but also highly customisable.
- Makes use of native Laravel features such as policies and form requests to make the shift easier for developers.
- Beautiful, expressive Nova-style schemas.
- Fully testable via expressive test helpers.
class PostSchemaextends Schema{/** * The model the schema corresponds to. * * @var string */publicstaticstring$model = Post::class;/** * The maximum include path depth. * * @var int */protectedint$maxDepth =3;/** * Get the resource fields. * * @return array */publicfunctionfields():array {return [ID::make(), BelongsTo::make('author')->type('users')->readOnly(), HasMany::make('comments')->readOnly(), Str::make('content'), DateTime::make('createdAt')->sortable()->readOnly(), DateTime::make('publishedAt')->sortable(), Str::make('slug'), BelongsToMany::make('tags'), Str::make('title')->sortable(), DateTime::make('updatedAt')->sortable()->readOnly(), ]; }/** * Get the resource filters. * * @return array */publicfunctionfilters():array {return [ WhereIdIn::make($this), WhereIn::make('author','author_id'), ]; }/** * Get the resource paginator. * * @return Paginator|null */publicfunctionpagination(): ?Paginator {return PagePagination::make(); }}
See our website,laraveljsonapi.io
New to JSON:API and/or Laravel JSON:API? ThentheLaravel JSON:API tutorialis a great way to learn!
Follow the tutorial to build a blog application with a JSON:API compliant API.
Install usingComposer
composer require laravel-json-api/laravel
See our documentation for further installation instructions.
When upgrading you typically want to upgrade this package and all our related packages. This is the recommended way:
composer require laravel-json-api/laravel --no-updatecomposer require laravel-json-api/testing --dev --no-updatecomposer up"laravel-json-api/*" cloudcreativity/json-api-testingTo view an example Laravel application that uses this package, see theTutorial Application.
Laravel JSON:API is open-sourced software licensed under theMIT License.
About
JSON:API for Laravel applications
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors9
Uh oh!
There was an error while loading.Please reload this page.