PHPackages                             willywes/apiresponse - 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. willywes/apiresponse

ActiveLibrary[API Development](/categories/api)

willywes/apiresponse
====================

Class to generate a standard structure for api json responses

v1.7.0(2y ago)01.9k1MITPHP

Since Oct 22Pushed 2y ago1 watchersCompare

[ Source](https://github.com/Willywes/ApiResponse)[ Packagist](https://packagist.org/packages/willywes/apiresponse)[ Docs](https://github.com/Willywes/ApiResponse)[ RSS](/packages/willywes-apiresponse/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (3)Versions (17)Used By (0)

ApiResponse
===========

[](#apiresponse)

[![Latest Version on Packagist](https://camo.githubusercontent.com/b01d34c753734abcece51df9b977d1571a4df694487a496cd1f1db0cbd5aa54c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f77696c6c797765732f617069726573706f6e73652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/willywes/apiresponse)[![Total Downloads](https://camo.githubusercontent.com/c7c2442ef6ae1dae5d729aac9f73e4ad2c0bbe36efb67f7c511d3f4dd8956cd8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f77696c6c797765732f617069726573706f6e73652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/willywes/apiresponse)[![StyleCI](https://camo.githubusercontent.com/aa7bb37b239907bee35088373c09b3df5b737fbcf3615759449c8f4f83fb43bf/68747470733a2f2f7374796c6563692e696f2f7265706f732f3330363436343933362f736869656c64)](https://styleci.io/repos/306464936)

Class to generate a standard structure for api json responses.

Installation
------------

[](#installation)

Via Composer

```
$ composer require willywes/apiresponse
```

Usage
-----

[](#usage)

#### Imports

[](#imports)

```
use Willywes\ApiResponse\ApiResponse;
```

### Functions of Control (HTTP/200 OK)

[](#functions-of-control-http200-ok)

Default functions that always return a http 200 code, but have a control state.

#### Params

[](#params)

ParamDescription**data**array of data for response (allow null)**message**custom message to response (optional)**title**custom title to response (optional)#### Functions

[](#functions)

FunctionDescription**JsonSuccess**Response status "success" with HTTP 200**JsonError**Response status "error" with HTTP 200**JsonWarning**Response status "warning" with HTTP 200**JsonInfo**Response status "info" with HTTP 200**JsonFieldValidation**Response status "field\_validation" with HTTP 200**JsonFieldValidationError**Response status "field\_validation" with HTTP 422#### Examples

[](#examples)

##### Success example

[](#success-example)

```
//Execution in php
return ApiResponse::JsonSuccess([
        'user' => User::first(),
        'roles' => Role::all(),
    ]);
```

```
//Response
{
    "status":"success",
    "title":"Operación Exitosa.",
    "message": null,
    "data":{
        "user":{
            "id":1,
            "full_name":"John Smith",
            "email":"jsmith@test.cl",
            "role_id":1
        },
        "roles":[
            {
                "id":1,
                "name":"God Admin"
            },
            {
                "id":2,
                "name":"Administrator"
            }
        ]
    }
}
```

```
//HTTP Response
Status Code: 200 OK
```

##### Error example

[](#error-example)

```
//Execution in php
return ApiResponse::JsonError(null, 'something has gone wrong!', 'oops');
```

```
//Response
{
    "status":"error",
    "title":"oops",
    "message":"something has gone wrong!",
    "data": null
}
```

```
//HTTP Response
Status Code: 200 OK
```

### Functions with specific HTTP Code

[](#functions-with-specific-http-code)

Default functions that returns a specific http code, but in the same way the body responds

#### Params

[](#params-1)

ParamDescription**data**array of data for response (allow null)**message**custom message to response (optional)#### Functions Code HTTP 1XX

[](#functions-code-http-1xx)

Http CodeFunction NameDescription**100****Http100 or Continue**Response status "info" with HTTP 100**101****Http101 or SwitchingProtocols**Response status "info" with HTTP 101**102****Http102 or Processing**Response status "info" with HTTP 102**103****Http103 or EarlyHints**Response status "info" with HTTP 103#### Functions Code HTTP 2XX

[](#functions-code-http-2xx)

Http CodeFunction NameDescription**200****Http200 or Ok**Response status "success" with HTTP 200**201****Http201 or Created**Response status "success" with HTTP 201**202****Http202 or Accepted**Response status "success" with HTTP 202**203****Http203 or NonAuthoritativeInformation**Response status "success" with HTTP 203**204****Http204 or NoContent**Response status "success" with HTTP 204**205****Http205 or ResetContent**Response status "success" with HTTP 205**206****Http206 or PartialContent**Response status "success" with HTTP 206#### Functions Code HTTP 3XX

[](#functions-code-http-3xx)

Http CodeFunction NameDescription**300****Http300 or MultipleChoices**Response status "redirection" with HTTP 300**301****Http301 or MovedPermanently**Response status "redirection" with HTTP 301**302****Http302 or MovedTemporarily**Response status "redirection" with HTTP 302**303****Http303 or SeeOther**Response status "redirection" with HTTP 303**304****Http304 or NotModified**Response status "redirection" with HTTP 304**305****Http305 or UseProxy**Response status "redirection" with HTTP 305**307****Http307 or TemporaryRedirect**Response status "redirection" with HTTP 307**308****Http308 or PermanentRedirect**Response status "redirection" with HTTP 308#### Functions Code HTTP 4XX

[](#functions-code-http-4xx)

Http CodeFunction NameDescription**400****Http400 or BadRequest**Response status "error" with HTTP 400**401****Http401 or Unauthorized**Response status "error" with HTTP 401**402****Http402 or PaymentRequired**Response status "error" with HTTP 402**403****Http403 or Forbidden**Response status "error" with HTTP 403**404****Http404 or NotFound**Response status "error" with HTTP 404**405****Http405 or MethodNotAllowed**Response status "error" with HTTP 405**406****Http406 or NotAcceptable**Response status "error" with HTTP 406**407****Http407 or ProxyAuthenticationRequired**Response status "error" with HTTP 407**408****Http408 or RequestTimeout**Response status "error" with HTTP 408**409****Http409 or Conflict**Response status "error" with HTTP 409**410****Http410 or Gone**Response status "error" with HTTP 410**411****Http411 or LengthRequired**Response status "error" with HTTP 411**412****Http412 or PreconditionFailed**Response status "error" with HTTP 412**413****Http413 or RequestEntityTooLarge**Response status "error" with HTTP 413**414****Http414 or RequestUriTooLarge**Response status "error" with HTTP 414**415****Http415 or UnsupportedMediaType**Response status "error" with HTTP 415**416****Http416 or RequestedRangeNotSatisfiable**Response status "error" with HTTP 416**417****Http417 or ExpectationFailed**Response status "error" with HTTP 417**421****Http421 or MissDirectedRequest**Response status "error" with HTTP 421**422****Http422 or UnprocessableEntity**Response status "error" with HTTP 422**423****Http423 or Locked**Response status "error" with HTTP 423**424****Http424 or FailedDependency**Response status "error" with HTTP 424**426****Http426 or UpgradeRequired**Response status "error" with HTTP 426**428****Http428 or PreconditionRequired**Response status "error" with HTTP 428**429****Http429 or TooManyRequests**Response status "error" with HTTP 429**431****Http431 or RequestHeaderFieldsTooLarge**Response status "error" with HTTP 431**451****Http451 or UnavailableForLegalReasons**Response status "error" with HTTP 451#### Functions Code HTTP 5XX

[](#functions-code-http-5xx)

Http CodeFunction NameDescription**500****Http500 or InternalServerError**Response status "error" with HTTP 500**501****Http501 or NotImplemented**Response status "error" with HTTP 501**502****Http502 or BadGateway**Response status "error" with HTTP 502**503****Http503 or ServiceUnavailable**Response status "error" with HTTP 503**504****Http504 or GatewayTimeout**Response status "error" with HTTP 504**505****Http505 or HTTPVersionNotSupported**Response status "error" with HTTP 505**506****Http506 or VariantAlsoNegotiates**Response status "error" with HTTP 506**507****Http507 or InsufficientStorage**Response status "error" with HTTP 507**508****Http508 or LoopDetected**Response status "error" with HTTP 508**510****Http510 or NotExtended**Response status "error" with HTTP 510**511****Http511 or NetworkAuthenticationRequired**Response status "error" with HTTP 511#### Examples

[](#examples-1)

##### 404 Error example

[](#404-error-example)

```
//Execution in php
return ApiResponse::NotFound(null, 'object not found!');
// or
//Execution in php without params
return ApiResponse::NotFound();
// or
return ApiResponse::Http404();
```

```
//Response
{
   "status": "error",
   "message": "Not Found",
   "data": null
}
```

```
//HTTP Response
Status Code: 404 Not Found
```

##### 401 Error example

[](#401-error-example)

```
//Execution in php
return ApiResponse::Unauthorized();
// or
return ApiResponse::Http401();
```

```
//Response
{
   "status": "error",
   "message": "Unauthorized",
   "data": null
}
```

```
//HTTP Response
Status Code: 401 Unauthorized
```

##### 403 Error example

[](#403-error-example)

```
//Execution in php
return ApiResponse::Forbidden();
// or
return ApiResponse::Http403();
```

```
//Response
{
   "status": "error",
   "message": "Forbidden",
   "data": null
}
```

```
//HTTP Response
Status Code: 403 Forbidden
```

Credits
-------

[](#credits)

- [Alejandro Isla](https://github.com/willywes)

License
-------

[](#license)

license. Please see the [license file](license.md) for more information.

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 97.6% 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

Every ~70 days

Recently: every ~167 days

Total

16

Last Release

980d ago

Major Versions

v0.3.0 → v1.0.02021-07-20

### Community

Maintainers

![](https://www.gravatar.com/avatar/eb10db2c683da7b54ef4dd41d33a46e34e3b3ab306c2d97daad9adb2b4380959?d=identicon)[Willywes](/maintainers/Willywes)

---

Top Contributors

[![Willywes](https://avatars.githubusercontent.com/u/4291325?v=4)](https://github.com/Willywes "Willywes (40 commits)")[![FrancoCastelli99](https://avatars.githubusercontent.com/u/72705327?v=4)](https://github.com/FrancoCastelli99 "FrancoCastelli99 (1 commits)")

---

Tags

apijsonlaravelphpresponseapilaravellumenapi-responseapiresponseStandard Api Response

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/willywes-apiresponse/health.svg)

```
[![Health](https://phpackages.com/badges/willywes-apiresponse/health.svg)](https://phpackages.com/packages/willywes-apiresponse)
```

###  Alternatives

[spatie/laravel-fractal

An easy to use Fractal integration for Laravel applications

1.9k15.1M99](/packages/spatie-laravel-fractal)[mollie/laravel-mollie

Mollie API client wrapper for Laravel &amp; Mollie Connect provider for Laravel Socialite

3624.1M28](/packages/mollie-laravel-mollie)

PHPackages © 2026

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