Generate API in seconds.

Fully integrated with Laravel, take the advantage of a powerful API without destructuring your codebase.
Terminal
composer require lomkit/laravel-rest-api
php artisan rest:quick-start

Start your next project with a powerful API

Laravel built-in

Fully integrates with Laravel (Gates / relationships / ...)

Customizable

Benefit the power of full customization for your needs.

Powerful

The search operation gives your API consumers a lot of possibilities.

Secured

Control what your API exposes and avoid unwanted actions.

Documentation

Automatic documentation generation with a single command.

Reduce API calls

The mutate endpoints allows you to operate multiple operations in a single call.

First setup

First, define your resource

Terminal
  php artisan rest:resource UserResource
UserResource.php
  <?php

  namespace App\Rest\Resources;

  use App\Rest\Resource;

  class UserResource extends Resource
  {
    /**
    * The model the resource corresponds to.
    *
    * @var class-string<\Illuminate\Database\Eloquent\Model>
    */
    public static $model = \App\Models\User::class;
  }

After, create your controller

Terminal
  php artisan rest:controller UsersController
UsersController.php
  <?php

  namespace App\Rest\Controllers;

  use App\Rest\Controller;

  class UsersController extends Controller
  {
      /**
      * Fully-qualified resource class name
      */
      public static $resource = App\Resources\User::class;
  }

Finally, register the routes

api.php
  use \Lomkit\Rest\Facades\Rest;

  Rest::resource('users', \App\Rest\Controllers\UsersController::class)
  +--------+----------------------------+-------------------+
  | Method | URI                        | Name              |
  +--------+----------------------------+-------------------+
  | GET    | api/users                  | api.users.details |
  | POST   | api/users/search           | api.users.search  |
  | POST   | api/users/actions/{action} | api.users.operate |
  | POST   | api/users/mutate           | api.users.mutate  |
  | DELETE | api/users                  | api.users.destroy |
  +--------+----------------------------+-------------------+

Or use our Quick Start

It generated all the files listed above automatically !
Terminal
  php artisan rest:quick-start
Copyright © 2024