Download the PHP package redmarbakker/via-rest without Composer
On this page you can find all versions of the php package redmarbakker/via-rest. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download redmarbakker/via-rest
More information about redmarbakker/via-rest
Files in redmarbakker/via-rest
Informations about the package via-rest
A Laravel REST Provider. Plug-and-play module for creating REST API routes with models.
Installation
composer.json
:
Setting up a Model
app/Models/Order.php
:
Setting up a Controller
In this case we modify our create because we want to do something specific on a create. app/Http/Controllers/Api/OrderController.php
:
Configuring your routes
A basic model example. routes/api.php:
:
A basic controller example. routes/api.php
:
Configuring API routes with a relation
An example where there is an OneToMany relationship with orders. In this case an user can have multiple orders. Requesting this relation can be done with the following endpoint: /api/v1/users/1/orders. In this way orders can be fetched and an order can be created (GET, POST). routes/api.php
:
Configuring API routes with a custom endpoint
An example where a custom endpoint is added where the frist array value is the method and the second array value is the method. routes/api.php
:
app/Http/Controllers/Api/OrderController.php
:
Validation your requests
Requests will be pickedup automatically. The abstract layer who will simulate the REST structure, will look for the Request with the following namespace: {ModelPackageName}\Http\Requests\Api\{ModelName}\CreateRequest
, where in this case a create example were given. The following names will be used: FetchRequest
, FetchAllRequest
, CreateRequest
, UpdateRequest
& DestroyRequest
.
For example we will create a Request for our Order endpoint. app/Http/Requests/Api/Orders/CreateRequest.php
:
For custom routes, we can create Requests like the following code. In this example we use the previous senario where we gonna create a "UnhandledRequest". app/Http/Requests/Api/Orders/UnhandledRequest.php
:
Response Examples
GET: /api/v1/users/1
:
GET: /api/v1/users
:
GET: /api/v1/users/1/orders
:
All versions of via-rest with dependencies
dees040/laravel-api-responses Version ^0.2.3
fideloper/proxy Version ^4.0
laravel/framework Version 5.8.*
laravel/tinker Version ^1.0