Skip to content

Simple Laravel package for creating API responses, compliant with JSend and the HTTP standard.

License

Notifications You must be signed in to change notification settings

firebit/laravel-api-response

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Firebit logo

Laravel API Response

This package aims to makes responses from the API consistent and easy to use. It is compliant with the HTTP standard and the JSend standard.

Example

Code

function getUser($id){
    // Get the data we wish to return
    $user = User:find($id);
    
    // If the user does not exist we return an error
    if(!$user){
        return ApiResponseFactory::notFound("User does not exist");
    }
    
    // Return the data by using a ReponseFactory
    return ApiResponseFactory::success($user);
}

Error output

{
  "status":"fail",
  "message":"User does not exist"
}

Success output

{
  "status":"success",
  "data": { 
      "id":1,
      "name":"John Doe",
      "email":"[email protected]",
      "created_at":null,
      "updated_at":null
  }
}

Installation

To install you can use Composer, use the following command to install this package.
composer require firebit/laravel-api-response

Documentation

Coming soon!

Progress

  • JSend compliance
  • PHPUnit tests
  • Documentation

License

For the license please check the LICENSE file, this project has the MIT license.

About

Simple Laravel package for creating API responses, compliant with JSend and the HTTP standard.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages