mpstr24 / laravel-api-responses
Laravel package for formatted API responses.
Installs: 1
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:package
Requires
- php: ^8.0
Requires (Dev)
- larastan/larastan: ^2.0 || ^3.0
- laravel/pint: ^1.14
- orchestra/testbench: ^10.0.0||^9.0.0||^8.22.0
- pestphp/pest: ^2.0 || ^3.0
- pestphp/pest-plugin-laravel: ^2.0 || ^3.0
- phpunit/phpunit: ^9.4|^10.1|^11.5
This package is auto-updated.
Last update: 2025-07-12 20:52:49 UTC
README
This package provides API response functions via a trait to help improve consistency of API response codes across your projects.
Features
- Pre-made functions of the most common API responses.
Installation
Install the package via Composer:
composer require mpstr24/laravel-api-responses
Usage/Examples
First add the trait to your controller.
use ApiResponseTrait;
All methods, except from "No Content" allow for a message and data to be returned. Custom messages also allow you to choose the status code.
Examples of each below.
Success - 200
public function success() { return $this->apiSuccess(); }
Created - 201
public function created() { return $this->apiCreated(); }
Accepted - 202
public function accepted() { return $this->apiAccepted(); }
No Content - 204
public function noContent() { return $this->apiNoContent(); }
Bad Request - 400
public function badRequest() { return $this->apiBadRequest(); }
Unauthorized - 401
public function unauthorized() { return $this->apiUnauthorized(); }
Forbidden - 403
public function forbidden() { return $this->apiForbidden(); }
Not Found - 404
public function notFound() { return $this->apiNotFound(); }
Teapot - 418
public function teapot() { return $this->apiTeapot(); }
Unprocessable - 422
public function unprocessable() { return $this->apiUnprocessable(); }
Too Many Requests - 429
public function tooManyRequests() { return $this->apiTooManyRequests(); }
Server Error - 500
public function serverError() { return $this->apiInternalServerError(); }
Custom response
public function apiCustomResponse() { return $this->apiCustom('Custom', null, 201); }
Roadmap
- Support for resources
- Expand into more helpful API features
- Larastan goals
- 5
- 6
- 7
- 8
- 9