An open API service indexing awesome lists of open source software.

https://github.com/ml-opensource/rest-api-server

A framework for rapid REST API development.
https://github.com/ml-opensource/rest-api-server

Last synced: 4 months ago
JSON representation

A framework for rapid REST API development.

Awesome Lists containing this project

README

          

Laravel API Server [![Slack Status](https://fuzz-opensource.herokuapp.com/badge.svg)](https://fuzz-opensource.herokuapp.com/)
==================

A framework for rapid REST API development.

### Installation
1. Require the repository in your `composer.json`
1. Add the `ApiServerServiceProvider` to your application and publish its config `artisan vendor:publish --provider="Fuzz\ApiServer\Providers\ApiServerServiceProvider"`.
1. Extend the packaged route provider for your app:

```
succeed('Foobar!');
}
}

Route::get('some-endpoint', 'MySpecificController@someEndpoint');
// ...
Route::controller(null, 'MyBaseController');
```
### ResourceControllers
Resource controllers extend functionality of `fuzz/magic-box` repositories and provide CRUD and authorization functionality out of the box.

Your application should extend the base `fuzz/api-server` Resource controller:

```
restful('User');`. The `restful` route macro is defined in `Fuzz\ApiServer\Providers\RouteServiceProvider`.

If any resources need to override the default functionality, you can create a specific ResourceController by extending your application's base ResourceController:

`app/Http/Controllers/Resources/Users.php`:

```
restful('Run', 'Resources\Users');`

### Returning that sweet, sweet, data
Send mixed data:

```
succeed(['foo' => 'bar']);
```
Send any arrayable data:

```
succeed(Model::all());
```
Send any paginated data:

```
succeed(Model::paginate($this->getPerPage(Model::DEFAULT_PER_PAGE)));
```
Send RESTful errors with error codes and optional data:

```
badRequest('That button does not do what you think it does.');
$this->forbidden('Maybe next time.');
$this->notFound();
```
Raise RESTful error exceptions outside of the controller context:

```
requireParameters('foo', 'bar');
```
Read a list of certain parameters:

```
suggestParameters('foo', 'bar');
```
Special handling (with de-duplication) for reading arrays:

```
requireArrayParameter('stuff');
```
Handles nested JSON and form properties just fine:

```
requireParameters('foo', 'foo.bar.id');
```

### CORS Middleware
Configuring the CORS middleware is as simple as adding `Fuzz\ApiServer\Routing\CorsMiddleware` to the `$middleware` array in `app/Http/Kernel.php`.