Download the PHP package raditzfarhan/laravel-api-response without Composer

On this page you can find all versions of the php package raditzfarhan/laravel-api-response. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-api-response

Laravel API Response

Latest Stable Version Total Downloads License StyleCI

A fluent API response formatter for Laravel. Returns consistent JSON responses across your application with minimal boilerplate.

Requirements

Installation

The service provider is auto-discovered. No manual registration needed.

Basic Usage

Two styles are available — use whichever fits your preference:

Both return an Illuminate\Http\JsonResponse instance.

Success response:

Failed response:

Chaining

Build your response by chaining any combination of these methods before calling success() or failed():

Method Description
httpCode(int $code) Set the HTTP status code
message(string $message) Set the response message
data(mixed $data) Set the response data
errors(array $errors) Set validation/error details
meta(array $meta) Set metadata
links(array $links) Set pagination links
code(int\|string $code) Set an application-level error/status code
headers(array $headers) Set custom HTTP response headers

Application-Level Error Codes

Use code() to attach an application-specific error or status code alongside the HTTP status code:

The code field only appears when set. Manage your own code definitions using constants or enums in your application.

Custom HTTP Headers

Use headers() to attach custom HTTP response headers. Headers are sent with the response but never appear in the JSON body:

Shorthand Methods

Common HTTP responses have dedicated shorthand methods. All accept an optional $message parameter:

Pass a custom message to any of them:

Validation Errors

Paginated Collections

Pass a LengthAwarePaginator or AnonymousResourceCollection to collection():

Exception Handling

To ensure all API error responses — including Laravel's built-in exceptions — follow the same structure, register custom renderers in your exception handler.

Laravel 11+ (bootstrap/app.php):

Laravel 9 / 10 (app/Exceptions/Handler.php):

The $request->expectsJson() guard ensures non-API routes (web, Blade) are unaffected and still render the default HTML error pages.

Configuration

Publish the config file to customise key names and add global fields:

This creates config/laravel-api-response.php.

Rename Response Keys

Rename any of the default JSON keys globally without changing your application code:

Global Fields

Append fields to every response automatically. Supports static values and closures:

Every response will then include:

IDE Support

All chainable and shorthand methods are annotated with @method PHPDoc on both the ApiResponse class and the facade, giving full autocomplete in PhpStorm, VS Code, and other IDEs.

Change log

Please see the changelog for more information on what has changed recently.

Credits

License

MIT. Please see the license file for more information.


All versions of laravel-api-response with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
illuminate/support Version ^9.0|^10.0|^11.0|^12.0|^13.0
illuminate/http Version ^9.0|^10.0|^11.0|^12.0|^13.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package raditzfarhan/laravel-api-response contains the following files

Loading the files please wait ...