Thursday, September 14, 2023
HomePHPGenerate Apis with ease with Laravel Relaxation Api

Generate Apis with ease with Laravel Relaxation Api


Laravel Relaxation Api is a bundle designed that will help you generate your Api in a robust approach with out restructuring your codebase. It integrates the next options:

  • Full REST API
  • Automated gates integration
  • All Laravel’s relationships help
  • Absolutely customisable
  • Secured via the entire course of
  • Complicated filtering operations
  • Mutate a number of fashions utilizing one endpoint
  • Automated documentation technology with customisation help

Putting in Laravel Relaxation Api

Set up the bundle utilizing composer:

composer require lomkit/laravel-rest-api

To start out utilizing the bundle, you’ve a fast begin command setting you up a full help API across the Person mannequin:

php artisan relaxation:quick-start

This command will generate the UserResource and UsersController courses and register them in your api.php route file.

And also you’re performed! The endpoints are absolutely registered; take a look at them utilizing the php artisan route:listing command:

+---------+--------------------------------+----------------------+

| Methodology | URI | Title |

+---------+--------------------------------+----------------------+

| GET | api/customers | api.customers.element |

| POST | api/customers/search | api.customers.search |

| POST | api/customers/actions/{motion} | api.customers.function |

| POST | api/customers/mutate | api.customers.mutate |

| DELETE | api/customers | api.customers.destroy |

+---------+--------------------------------+----------------------+

To take a look at what’s attainable with these freshly registered endpoints, please take a look on the endpoint half of the documentation.

Here is an instance of the search endpoint potentialities:

// (POST) api/posts/search

{

"scopes": [

{"name": "withTrashed", "parameters": [true]}

],

"filters": [

{

"field": "id", "operator": ">", "value": 1, "type": "or"

},

{

"nested": [

{"field": "user.id", "operator": "<", "value": 2},

{"field": "id", "operator": ">", "value": 100, "type": "or"}

]

}

],

"kinds": [

{"field": "user_id", "direction": "desc"},

{"field": "id", "direction": "asc"}

],

"selects": [

{"field": "id"}

],

"consists of": [

{

"relation": "posts",

"filters": [

{"field": "id", "operator": "in", "value": [1, 3]}

],

"restrict": 2

},

{

"relation": "person",

"filters": [

{

"field": "languages.pivot.boolean",

"operator": "=",

"value": true

}

]

}

],

"aggregates": [

{

"relation": "stars",

"type": "max",

"field": "rate",

"filters": [

{"field": "approved", "value": true}

]

}

],

"directions": [

{

"name": "odd-even-id",

"fields": [

{ "name": "type", "value": "odd" }

]

}

],

"web page": 2,

"restrict": 10

}

Hyperlinks

The Laravel Relaxation Api bundle and documentation may be discovered on GitHub at lomkit/laravel-rest-api.

What’s subsequent

  • Frontend metrics help
  • Plain textual content search utilizing Laravel Scout
  • Aliases on consists of / aggregates
RELATED ARTICLES

Most Popular

Recent Comments