Laravel Restify is an extraordinary tool inspired by Laravel Nova for building robust, modern API. It is the fastest way to make a powerful JSON API compatible with Rest API with Laravel. If you already have an application built with Laravel Nova, you can transfer your data to Laravel Restify using basically the same resource classes content.
If you don't have an application written with Nova, you can start with Laravel Restify from scratch and get a powerful API in a few minutes.
Laravel Restify has a few requirements you should be aware of before installing it:
You can install this package via composer, Just run this command in the terminal:
composer require binaryk/laravel-restify
After the installation, the package requires a setup process:
php artisan restify:setup
The command above:
providers/RestifyServiceProviderand will add it in the
app/Restify/UserRepositoryrepository for users CRUD
Having the package setup and
users table migrated, you should be good to perform the first API request:
or using json api format:
This should return the users list paginated and formatted according to JSON:API standard.
As you notice the default prefix for the
restify API is
/api/restify. This can be changed from the
'base' => '/api/restify',
One important configuration is the
// config/restify.php 'middleware' => [ 'api', // 'auth:sanctum', Binaryk\LaravelRestify\Http\Middleware\DispatchRestifyStartingEvent::class, Binaryk\LaravelRestify\Http\Middleware\AuthorizeRestify::class, ]
Creating a new repository can be done via
php artisan restify:repository PostRepository
If you want to generate the
migration as well, then you can use the
php artisan restify:repository PostRepository --all
Since the authorization is using the Laravel Policies, a good way of generating a complete policy for an entity is by using the restify command:
php artisan restify:policy PostPolicy
Above are the details of the basic setup & configurations if you want to implement its Authentication & API setup, you can visit its complete details on its documentation and source code on Github.
Published at : 18-02-2022
I am a highly results-driven professional with 12+ years of collective experience in the grounds of web application development especially in laravel, native android application development in java, and desktop application development in the dot net framework. Now managing a team of expert developers at Codebrisk.