PHPackages                             uglymanfirst/laravel-api\_responses - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. uglymanfirst/laravel-api\_responses

ActiveLibrary[API Development](/categories/api)

uglymanfirst/laravel-api\_responses
===================================

It's a Laravel format for an API responses.

1.0.2(8y ago)210GNU General Public License v3.0PHPPHP &gt;=5.3.0

Since Jul 18Pushed 1y ago1 watchersCompare

[ Source](https://github.com/raphaisdev/laravel-api_responses)[ Packagist](https://packagist.org/packages/uglymanfirst/laravel-api_responses)[ RSS](/packages/uglymanfirst-laravel-api-responses/feed)WikiDiscussions master Synced yesterday

READMEChangelog (3)DependenciesVersions (3)Used By (0)

[![FTD Default API Response](https://github.com/uglymanfirst/laravel-api_responses/raw/master/docs/ftd-default-api-response-logo.png?raw=true)](https://github.com/uglymanfirst/laravel-api_responses/blob/master/docs/ftd-default-api-response-logo.png?raw=true)

Welcome to FTD Default API Response!
====================================

[](#welcome-to-ftd-default-api-response)

- About
- Installation
- How to use
    - **The success method**
    - **The paginate method**
    - **The error method**
    - **Advanced use for the success, paginate and error methods**
    - **The custom method**
    - **The defaultStatusCode method**
    - **The code list for defaultStatusCode method**

---

About
=====

[](#about)

This package was created to extend the **Laravel Framework** response system, and elevate him to the standard described on the [**{json:api}**](http://jsonapi.org) website[1](#user-content-fn-jsonapi-d2da4eb95998ee3d2f2cf994837dbd76).

The answers besides creating a more friendly and readable formatting also contemplate the control of the Headers according to the last code.

---

Installation
============

[](#installation)

Use composer do install our package:

```
composer require ftd/default-api-response
```

And call the provider inside your Laravel **/config/app.php** file:

```
    'providers' => [
    ...
        /*
         * FTD Default API Response
         */
         FTD\DefaultAPIResponse\DefaultAPIResponseServiceProvider::class,
    ],
```

Now it's done and we're ready to go!

---

How to use
==========

[](#how-to-use)

**FTD API Response** give us 5 new methods:

1. success
2. paginate
3. error
4. custom
5. defaultStatusCode

Every method has a particular way to use, but always easy.

**The success method**
----------------------

[](#the-success-method)

This method will throw a header status code **200** and put your content inside a **data** wrapper:

**Example:**

```
  public function index()
  {
      return response()->success(App\User::all());
  }
```

**Result:**

```
{
  "data": [
    {
      "id": 1,
      "name": "Rodolfo",
      "email": "rodolfo@ftdapi.com",
      "created_at": null,
      "updated_at": null
    },
    {
      "id": 2,
      "name": "Shirley",
      "email": "shirlei@ftdapi.com",
      "created_at": "2017-06-16 01:02:03",
      "updated_at": null
    }
  ]
}
```

**Example:**

```
  public function show(User $user)
  {
      return response()->success($user);
  }
```

**Result:**

```
{
  "data": {
    "id": 1,
    "name": "Rodolfo",
    "email": "rodolfo@ftdapi.com",
    "created_at": null,
    "updated_at": null
  }
}
```

**The paginate method**
-----------------------

[](#the-paginate-method)

This method will throw a header status code **200** and put your content inside a **data** wrapper, and create another wrapper called **meta**, for the pagination properties:

**Example:**

```
  public function index()
  {
      $users = App\User::paginate(2);
    return response()->paginate($users);
  }
```

**Result:**

```
{
  "meta": {
    "pagination": {
      "current_page": 2,
      "from": 3,
      "last_page": 3,
      "next_page_url": "http://ftdapi.com/api?page=3",
      "path": "http://ftdapi.com/api",
      "per_page": 2,
      "prev_page_url": "http://ftdapi.com/api?page=1",
      "to": 4,
      "total": 6
    }
  },
  "data": [
    {
      "id": 3,
      "name": "Marley",
      "email": "marley@ftdapi.com",
      "created_at": "2017-06-15 00:00:01",
      "updated_at": null
    },
    {
      "id": 4,
      "name": "Steve",
      "email": "steve@ftdapi.com",
      "created_at": "2017-06-16 01:02:03",
      "updated_at": null
    }
  ]
}
```

**The error method**
--------------------

[](#the-error-method)

This method will throw a header status code **400** and put your content inside a **errors** wrapper:

**Example:**

```
  //User Custom Request
  public function rules()
  {
    return [
        'name'      => 'required|string|max:255',
        'username'  => 'required|unique:users|string|max:255',
        'password'  => 'required|string|max:255'
    ];
  }

  ...

  public function response(array $errors)
  {
    return response()->error($errors);
  }
```

**Result:**

```
{
  "errors": [
    "Name must be provided.",
    "Username must be provided.",
    "Password must be provided."
  ]
}
```

**Advanced use for the success, paginate and error methods**
------------------------------------------------------------

[](#advanced-use-for-the-success-paginate-and-error-methods)

If you need change the default status code of this methods, you can give a second parameter, like:

```
  ...
  return response()->success($data, 201);

  ...
  return response()->paginate($data, 206);

  ...
  return response()->error($data, 401);
```

**The custom method**
---------------------

[](#the-custom-method)

This method is used for who need more control of the entire response:

- The default **content** is **null**
- The default **header status code** is **200**
- The default **extra headers** is **null**
- The default **header content type** is **'application/json'**

**Example:**

```
  public function myCustomMethod()
  {
    return response()->custom(
      $content = [
            "Name" => "Rodolfo",
            "Age"=>13
            ],
      $status = 200,
      $headers = ["X-USER-INFO" => TRUE],
      $headerContentType = 'application/json'
    );
  }
```

**Result:**In your header you will see the:

```
  "X-USER-INFO" : true
```

or

```
  "X-USER-INFO" : 1
```

Depends on which browser you are using.

And, finally, the response body will receive the contents, but **without** the default **data** wrapper:

```
{
  "Name": "Rodolfo",
  "Age": 13
}
```

If you need to force download of a PDF file, for example, this method is the right way to do it.

**The defaultStatusCode method**
--------------------------------

[](#the-defaultstatuscode-method)

This method will throw a header status code and depends on which code, put default message content inside a **data** or **errors** wrapper:

**Example:**

```
  public function store()
  {
    return response()->defaultStatusCode(400);
  }
```

**Result:**

```
{
  "errors": [
    "Bad Request"
  ]
}
```

**The code list for defaultStatusCode method**
----------------------------------------------

[](#the-code-list-for-defaultstatuscode-method)

CodeReference102'Processing',200'OK',201'Created',202'Accepted',203'Non-authoritative Information',204'',//No Content206'Partial Content',207'Multi-Status',302'Found',304'Not Modified',400'Bad Request',401'Unauthorized',402'Payment Required',403'Forbidden',404'Not Found',405'Method Not Allowed',406'Not Acceptable',409'Conflict',413'Payload Too Large',415'Unsupported Media Type',416'Requested Range Not Satisfiable',422'Unprocessable Entity',423'Locked',424'Failed Dependency',500'Internal Server Error',501'Not Implemented',503'Service Unavailable'---

If you need more information about status code, the [HTTP Status Codes](https://httpstatuses.com/) website[2](#user-content-fn-statuscodes-d2da4eb95998ee3d2f2cf994837dbd76) may help you.

Footnotes
---------

1. **{json:api}** A specification for building apis in json. [↩](#user-content-fnref-jsonapi-d2da4eb95998ee3d2f2cf994837dbd76)
2. **httpstatuses.com** is an easy to reference database of HTTP Status Codes with their definitions and helpful code references all in one place. [↩](#user-content-fnref-statuscodes-d2da4eb95998ee3d2f2cf994837dbd76)

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance29

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

3220d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1247158?v=4)[Raphael](/maintainers/raphaisdev)[@raphaisdev](https://github.com/raphaisdev)

---

Top Contributors

[![raphaisdev](https://avatars.githubusercontent.com/u/1247158?v=4)](https://github.com/raphaisdev "raphaisdev (2 commits)")

---

Tags

apiapi-responseapi-restapi-restfulllaravellaravel-5-packagelaravel-frameworklaravel-packagelaravel5laravel5-packagepackagephpphp-library

### Embed Badge

![Health badge](/badges/uglymanfirst-laravel-api-responses/health.svg)

```
[![Health](https://phpackages.com/badges/uglymanfirst-laravel-api-responses/health.svg)](https://phpackages.com/packages/uglymanfirst-laravel-api-responses)
```

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M480](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M272](/packages/twilio-sdk)[knplabs/github-api

GitHub API v3 client

2.2k15.8M187](/packages/knplabs-github-api)[facebook/php-business-sdk

PHP SDK for Facebook Business

90121.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

73813.7M114](/packages/meilisearch-meilisearch-php)[google/gax

Google API Core for PHP

263103.1M454](/packages/google-gax)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
