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.
- Host: GitHub
- URL: https://github.com/ml-opensource/rest-api-server
- Owner: ml-opensource
- License: mit
- Created: 2016-07-07T20:53:52.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2022-10-21T18:51:04.000Z (over 3 years ago)
- Last Synced: 2024-12-11T15:49:30.106Z (about 1 year ago)
- Language: PHP
- Size: 371 KB
- Stars: 6
- Watchers: 23
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
Laravel API Server [](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`.