evgeny-l / rest-api-core by evgeny-l

REST API Core. Handles REST API requests and responses.
907
2
2
Package Data
Maintainer Username: evgeny-l
Maintainer Contact: e.leksunin@gmail.com (Evgeny Leksunin)
Package Create Date: 2017-05-11
Package Last Update: 2022-03-10
Language: PHP
License: MIT
Last Refreshed: 2024-12-15 15:18:11
Package Statistics
Total Downloads: 907
Monthly Downloads: 0
Daily Downloads: 0
Total Stars: 2
Total Watchers: 2
Total Forks: 2
Total Open Issues: 0

Laravel 5 REST API Core

Install

Require this package with composer using the following command:

composer require evgeny-l/rest-api-core

After updating composer, add the service provider to the providers array in config/app.php

EvgenyL\RestAPICore\RestAPICoreServiceProvider::class,

Publish the config file to config/rest-api-core.php

php artisan vendor:publish --provider="EvgenyL\RestAPICore\RestAPICoreServiceProvider" --tag=config

Install exceptions handler to app/Exceptions/Handler.php:

use EvgenyL\RestAPICore\Http\Exceptions\APIJSONHandlerTrait;

...
    public function render($request, Exception $exception)
    {
        if ($request->expectsJson()) {
            return $this->handleJSONResponse($request, $exception);
        }
        return parent::render($request, $exception);
    }
    
...

Install response middleware for JSON formatting into API middleware section:

\EvgenyL\RestAPICore\Http\Middleware\ResponseFormat::class