Skip to content

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

License

Notifications You must be signed in to change notification settings

AbdulBasetRS/Response-Format-Trait

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Documentation

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.

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages