abdulbaset/response-format-trait

A PHP package for standardizing and formatting API and web responses.

1.0.6 2024-01-06 04:59 UTC

This package is auto-updated.

Last update: 2024-05-06 05:43:40 UTC


README

Response-Format-Trait

This PHP package provides a simple and consistent way to format API and web responses. It includes a set of predefined HTTP status codes with detailed messages and supports both API and web response formatting. The package is designed to be easy to integrate into any PHP project, with a particular focus on Laravel applications.

Features

  • Standardized API and web response formatting.
  • Predefined HTTP status codes with detailed messages.
  • Easy integration into Laravel projects.

Installation

Use Composer to install the package:

You can install this package via Composer:

composer require abdulbaset/response-format-trait

Usage

after installing the package you should include the namespace, see the following code:

use Abdulbaset\ResponseFormatTrait\Respond;

for use toApi method, see the following code:

echo Respond::toApi(200);
  • use, Screenshot 1

  • output, Screenshot 1

for use all parameters in toApi method, see the following code:

echo Respond::toApi(
        200, // status
        'successful response', // message
        'details response with status code 200', // details
        ['testOne', 'testTwo'] // data
    );
  • use, Screenshot 1

  • output, Screenshot 1

for use getStatusCodeSupported method to get all Status Supported with message and details, see the following code:

echo json_encode(Respond::getStatusCodeSupported());
  • use, Screenshot 1

  • output, Screenshot 1

Author

License

This Response Format Package PHP Package is open-source software licensed under the MIT License.