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

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

Tests Latest Version on Packagist Total Downloads DOI License Laravel News PHP Version Laravel Version

Laravel API Toolkit

stackmasteraliza/laravel-api-response

The all-in-one Laravel API solution: Standardized Responses + Auto-generated Swagger Docs + Export to Postman & Insomnia

A clean and consistent API response builder for Laravel applications. This package provides a simple and elegant way to build standardized JSON responses for your APIs with zero-config OpenAPI documentation.

Aliza Ali
Developed by Aliza Ali
Creator & Maintainer

Features

Installation

You can install the package via composer:

The package will automatically register itself.

Publish Configuration (Optional)

Usage

Using the Facade

Using the Trait

Available Methods

Success Responses

Method Status Code Description
success($data, $message, $statusCode) 200 General success response
created($data, $message) 201 Resource created
accepted($data, $message) 202 Request accepted for processing
noContent() 204 No content to return

Error Responses

Method Status Code Description
error($message, $statusCode, $errors) Variable General error response
badRequest($message, $errors) 400 Bad request
unauthorized($message) 401 Unauthorized
forbidden($message) 403 Forbidden
notFound($message) 404 Resource not found
methodNotAllowed($message) 405 Method not allowed
conflict($message, $errors) 409 Conflict
unprocessable($message, $errors) 422 Unprocessable entity
validationError($errors, $message) 422 Validation failed
tooManyRequests($message, $retryAfter) 429 Too many requests
serverError($message) 500 Internal server error
serviceUnavailable($message) 503 Service unavailable

Response Structure

Success Response

Paginated Response

Cursor Paginated Response

Cursor pagination is more efficient for large datasets:

Error Response

Exception Handling

To use the built-in exception handler, update your bootstrap/app.php (Laravel 11+):

Or for Laravel 10, update your app/Exceptions/Handler.php:

Middleware

Use the ForceJsonResponse middleware to ensure all API responses are JSON:

Adding Custom Data

Response Macros

Define reusable custom response types using macros:

Usage:

Testing Helpers

The package provides convenient testing assertions for your API tests:

Available Test Assertions

Method Description
assertApiSuccess() Assert response has success: true
assertApiError($statusCode) Assert response has success: false and optional status code
assertApiStatusCode($code) Assert status code in response body
assertApiMessage($message) Assert response message
assertApiHasData($key) Assert data exists (optionally check for specific key)
assertApiDataCount($count) Assert data array has specific count
assertApiData($expected) Assert data equals expected array
assertApiDataContains($expected) Assert data contains expected subset
assertApiPaginated() Assert response has pagination meta
assertApiCursorPaginated() Assert response has cursor pagination meta
assertApiHasErrors($key) Assert errors exist (optionally check for specific key)

OpenAPI/Swagger Documentation

The package automatically generates OpenAPI 3.0 documentation from your API routes with a beautiful, modern dark-themed UI - no additional coding required!

Export to Multiple Formats

Export your API documentation to Postman, Insomnia, JSON, or YAML with a single click.

Built-in Authorization

Easily configure Bearer Token or API Key authentication directly from the UI.

WebSocket Tester

Test WebSocket connections directly from the documentation with real-time message sending and receiving.

Zero-Configuration Auto-Generation

The package intelligently generates documentation by:

No FormRequest or PHP attributes required! Just write your Laravel code normally and get instant API documentation.

Note: FormRequest classes are completely optional. If you don't use them, the package will still generate documentation - it will just show a generic request body schema for POST/PUT/PATCH endpoints. Using FormRequest simply provides richer, more detailed request body documentation.

View Documentation

Simply visit /api-docs in your browser to see the interactive Swagger UI:

Custom Swagger UI Features

The package includes a beautifully designed custom Swagger UI with:

Export API Documentation

Export your API documentation directly from the Swagger UI to import into your preferred tools. Click the Export button in the header to access the following formats:

OpenAPI Specification

API Client Collections

All exports are generated client-side for instant downloads with no server load.

Customization

Configure the Swagger UI appearance in your .env file:

Or in your config file:

API Endpoints

Endpoint Description
GET /api-docs Interactive Swagger UI
GET /api-docs/openapi.json Raw OpenAPI 3.0 specification

Generate Static File

Generate a static OpenAPI JSON file:

This creates public/api-docs/openapi.json that you can use with any OpenAPI-compatible tool.

Enhanced Documentation with Attributes (Optional)

For more detailed or customized documentation, you can optionally add PHP attributes to your controller methods:

Available Attributes

Attribute Target Description
#[ApiEndpoint] Method Define summary, description, tags, deprecated status
#[ApiRequest] Method Define query/path parameters
#[ApiRequestBody] Method Define request body schema
#[ApiResponse] Method Define response status, description, example

Built-in Schema References

Use these in #[ApiResponse(ref: '...')]:

Configuration

Disabling Status Code in Response Body

If you prefer not to include the status code in the response body, you can disable it:

Or in your config file:

API Versioning

The package supports versioned API documentation. When enabled, it auto-detects version prefixes from your routes (e.g., api/v1/*, api/v2/*) and generates separate OpenAPI specs for each version with a version switcher in the Swagger UI.

Enable Versioning

Add to your .env file:

Or in your config file (config/api-response.php):

Custom Version Definitions

For more control, you can define custom version patterns:

Versioned Endpoints

When versioning is enabled, the following endpoints become available:

Endpoint Description
/api-docs Swagger UI with version switcher
/api-docs/openapi.json Full OpenAPI spec (all versions)
/api-docs/versions List of available versions
/api-docs/v1/openapi.json OpenAPI spec for v1 only
/api-docs/v2/openapi.json OpenAPI spec for v2 only

WebSocket Testing

The Swagger UI includes a built-in WebSocket tester for testing real-time connections directly from the documentation.

Features

Configuration

Click the WebSocket button in the Swagger UI header to open the tester.

Testing

Contributing

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

License

The MIT License (MIT). Please see License File 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
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 stackmasteraliza/laravel-api-response contains the following files

Loading the files please wait ...