thuraaung2493 / laravel-api-helpers
A simple package for creating API endpoints with Laravel.
dev-main
2023-09-10 04:26 UTC
Requires
- php: ^8.2
- illuminate/support: ^10.12
- laravel/sanctum: ^3.2
- thecodingmachine/safe: ^2.5
Requires (Dev)
- laravel/pint: ^1.10
- nunomaduro/larastan: ^2.0
- nunomaduro/mock-final-classes: ^1.2
- orchestra/testbench: ^8.5
- pestphp/pest: ^2.6
- thecodingmachine/phpstan-safe-rule: ^1.2
This package is auto-updated.
Last update: 2025-01-10 07:30:26 UTC
README
It supports Laravel 9+ and PHP 8.1+
Description
This package contains many utility classes that assist in API creation.
Installation
Laravel
Require this package with composer using the following command:
composer require thuraaung2493/laravel-api-helpers@dev
Usage
Helper Classes for Json API Responses
All API Response classes implement the Responsable interface.
Response Formats see in responses.json
// Response Format for ModelResponse|CollectionResponse|MessageResponse|TokenResponse { "data": "", "message": "Success.", "status": 200 } // Response Format for ApiErrorResponse { "title": "Error!", "description": "Error Description", "status": 500 } // Response Format for ApiValidationErrorsResponse { "title": "Error!", "errors": [], "status": 422 }
Middleware Classes
To change default headers in config
php artisan vendor:publish --tab=api-helpers
DataObjects
Example
$accept = Accept::of( type: ContentType::JSON ); // Turn to Header $accept->asHeader(); // new Header( // key: 'Accept', // value: 'application/json', // ); // Turn to headers array $accept->headers(); // [ // 'Accept' => 'application/json', // ]