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

On this page you can find all versions of the php package dantepiazza/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

dantepiazza/laravel-api-response

A fluent, expressive JSend-compliant JSON API response builder for Laravel 10+.

Implements the JSend specification: every response carries a status of success, fail, or error, making frontend handling predictable and consistent by convention.


Installation

The service provider and ApiResponse facade are auto-discovered via Laravel's package discovery. No additional setup required.

Publish config (optional)


Usage

Three ways to use the package — all share the same singleton instance and are fully interchangeable:

For a clean DI setup across all controllers, inject in the base Controller:


Response structure

The envelope follows the JSend standard. The code field mirrors the HTTP status code and is always present in the body for clients that don't inspect headers.

success — 2xx

data is always present. It will be null if nothing was provided.
message is optional for success and fail.

fail — 4xx

Client-side error. data describes what went wrong (e.g. validation errors).

error — 5xx

Server-side error. message is required by JSend. data is optional.


API Reference

2xx — success

Method HTTP Notes
success(mixed $data = null, string $message) 200 Standard success
created(mixed $data = null, string $message) 201 Resource created
accepted(mixed $data = null, string $message) 202 Async / queued
noContent() 204 No body

4xx — fail

Method HTTP Default message
badRequest(mixed $data = null, string $message) 400 The request parameters are incorrect.
unauthorized(mixed $data = null, string $message) 401 Unauthorized
forbidden(mixed $data = null, string $message) 403 Forbidden
notFound(mixed $data = null, string $message) 404 Not found
methodNotAllowed(mixed $data = null, string $message) 405 Method not allowed
conflict(mixed $data = null, string $message) 409 Conflict
validationError(mixed $data = null, string $message) 422 Validation failed
tooManyRequests(mixed $data = null, string $message) 429 Too many requests

5xx — error

Method HTTP Default message
serverError(mixed $data = null, string $message) 500 Internal server error
serviceUnavailable(mixed $data = null, string $message) 503 Service unavailable

Generic setter

Use when you need full control, e.g. inside a macro:


Data helpers

Merging extra data

Multiple ->data() calls merge into the same array.

Message-only override

Validation errors

Pass errors directly as $data — they land in data per the JSend spec:


Pagination

Laravel paginator (automatic)

Pass a LengthAwarePaginator directly — all fields are extracted automatically:

Manual array / Collection

If total is omitted it defaults to count($items).

Pagination output

Both cases produce the same structure:


Cookies


Configuration

After publishing the config you can rename any top-level JSON key to match an existing API contract:


Macros

Extend the class with custom shorthand methods in any service provider:


Supported data types

data(), records(), and the $data argument of all shorthand methods accept:


Frontend — TypeScript model

The package ships ApiResponse.ts, a single TypeScript class that maps the JSend envelope into a typed object.

Safe factory (returns null instead of throwing on invalid input):


Testing


License

MIT


All versions of laravel-api-response with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3
illuminate/http Version ^10.0|^11.0|^12.0|^13.0
illuminate/support Version ^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 dantepiazza/laravel-api-response contains the following files

Loading the files please wait ...