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

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

A lightweight, zero-config package that gives your Laravel API a consistent JSON response format — so every endpoint speaks the same language.

Why?

Without a standard response helper, API responses across your app end up looking different — some return status, others return success, error formats vary, and pagination metadata is inconsistent. This package solves that with a single static class and an optional trait.

Before:

After:

Every response follows the same structure. Every time.

Requirements

Installation

The service provider is auto-discovered — no manual registration needed.

Quick Start

Example JSON response:

Usage

Choose The Right Place For Extra Data

Use each part of the response for a specific purpose:

Example:

Static Class

Use ApiResponse directly anywhere in your application:

Common Real-World Snippets

1. Return a single resource

2. Return a newly created resource

3. Return validation errors

4. Return custom top-level fields

5. Return an API token after login

6. Return an empty 204 response

noContent() returns HTTP 204 with an empty response body. That matches HTTP semantics and avoids clients discarding a JSON payload.

Pagination

Wrap Laravel's paginator to include pagination metadata automatically:

Response:

You can also pass extra metadata:

And if you need custom top-level fields outside meta:

Authentication / Token Response

Return a token with optional user data — works with Sanctum, JWT, or any token-based auth:

Response:

Controller Trait

Prefer $this-> syntax? Add the ApiResponder trait to your controller or a base controller:

Then use it in any controller:

Trait example with extra fields:

Response Format

All responses follow a consistent JSON structure:

Success:

Success with metadata:

Success with custom top-level fields:

No content:

HTTP 204 with an empty body.

Error:

Error with details:

API Reference

Static Methods (ApiResponse)

Method Status Description
success($data, $message, $statusCode, $meta, $additional) 200 General success
created($data, $message, $meta, $additional) 201 Resource created
noContent($message, $additional) 204 No content, empty non-JSON body
error($message, $statusCode, $errors, $additional) 400 General error
unauthorized($message, $additional) 401 Authentication required
forbidden($message, $additional) 403 Access denied
notFound($message, $additional) 404 Resource not found
validationError($errors, $message, $additional) 422 Validation failed
serverError($message, $additional) 500 Internal server error
paginated($paginator, $message, $meta, $additional) 200 Paginated collection
withToken($token, $user, $tokenType, $message, $meta, $additional) 200 Auth token response

Reserved keys:

If a developer passes any of these inside $additional, the package ignores them so the response contract stays stable.

Trait Methods (ApiResponder)

Trait Method Calls
$this->successResponse(...) ApiResponse::success()
$this->errorResponse(...) ApiResponse::error()
$this->createdResponse(...) ApiResponse::created()
$this->noContentResponse(...) ApiResponse::noContent()
$this->notFoundResponse(...) ApiResponse::notFound()
$this->unauthorizedResponse(...) ApiResponse::unauthorized()
$this->forbiddenResponse(...) ApiResponse::forbidden()
$this->validationErrorResponse(...) ApiResponse::validationError()
$this->serverErrorResponse(...) ApiResponse::serverError()
$this->paginatedResponse(...) ApiResponse::paginated()
$this->tokenResponse(...) ApiResponse::withToken()

Testing

If your machine has multiple PHP versions installed, make sure you run tests with a supported version for your current dependency lock file. Example:

Recommended pre-publish check:

Then install the package in a fresh Laravel app and verify a real route:

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

The MIT License (MIT). Please see LICENSE for more information.


All versions of laravel-api-response with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
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 haseebmirza/laravel-api-response contains the following files

Loading the files please wait ...