PHPackages                             nicklaw5/larapi - 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. nicklaw5/larapi

ActiveLibrary[API Development](/categories/api)

nicklaw5/larapi
===============

A simple Laravel 5 class for handling json api responses.

3.0.1(9y ago)111.5k1MITPHPPHP &gt;=5.5.9

Since Nov 6Pushed 9y ago4 watchersCompare

[ Source](https://github.com/nicklaw5/larapi)[ Packagist](https://packagist.org/packages/nicklaw5/larapi)[ RSS](/packages/nicklaw5-larapi/feed)WikiDiscussions master Synced today

READMEChangelog (7)DependenciesVersions (12)Used By (0)

Larapi
======

[](#larapi)

A simple Laravel 5 package for handling common HTTP API responses in JSON form.

Docs
----

[](#docs)

You can find [v2.x docs here](docs/v2x-docs.md). For the lastest (v3.x) docs see below.

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

[](#installation)

Pull in Larapi via composer:

```
$ composer require nicklaw5/larapi
```

Then, add the following **Service Provider** to your `providers` array in your `config/app.php` file:

```
'providers' => array(
	...
	Larapi\LarapiServiceProvider::class,
);
```

Usage
-----

[](#usage)

\###Succes Responses### Available responses:

```
Larapi::ok();           // 200 HTTP Response
Larapi::created();      // 201 HTTP Response
Larapi::accepted();     // 202 HTTP Response
Larapi::noContent();    // 204 HTTP Response
```

**Example: Return HTTP OK**

This:

```
// app/Http/routes.php

Route::get('/', function()
{
	return Larapi::ok();
});
```

will return:

```
{
	"success": true
}
```

with these headers:

```
HTTP/1.1 200 OK
Content-Type: application/json

```

**Example: Return HTTP OK with Response Data**

This:

```
// app/Http/routes.php

Route::get('/', function()
{
	$data = [
		['id' => 1, 'name' => 'John Doe', 'email' => 'john@doe.com'],
		['id' => 2, 'name' => 'Jane Doe', 'email' => 'jane@doe.com']
	];

	return Larapi::ok($data);
});
```

will return:

```
{
	"success": true,
	"response": [
		{
			"id": 1,
			"name": "John Doe",
			"email": "john@doe.com"
		},
		{
			"id": 2,
			"name": "Jane Doe",
			"email": "jane@doe.com"
		}
	]
}
```

with these headers:

```
HTTP/1.1 200 OK
Content-Type: application/json

```

**Example: Return HTTP OK with Custom Response Headers**

This:

```
// app/Http/routes.php

Route::get('/', function()
{
	$data = [
		['id' => 1, 'name' => 'John Doe', 'email' => 'john@doe.com'],
		['id' => 2, 'name' => 'Jane Doe', 'email' => 'jane@doe.com']
	];

	$headers = [
		'Header-1' => 'Header-1 Data',
		'Header-2' => 'Header-2 Data'
	];

	return Larapi::ok($data, $headers);
});
```

will return:

```
{
	"success": true,
	"response": [
		{
			"id": 1,
			"name": "John Doe",
			"email": "john@doe.com"
		},
		{
			"id": 2,
			"name": "Jane Doe",
			"email": "jane@doe.com"
		}
	]
}
```

with these headers:

```
HTTP/1.1 200 OK
Content-Type: application/json
Header-1: Header-1 Data
Header-2: Header-2 Data

```

\###Error Responses###

Available responses:

```
Larapi::badRequest();           // 400 HTTP Response
Larapi::unauthorized();         // 401 HTTP Response
Larapi::forbidden();            // 403 HTTP Response
Larapi::notFound();             // 404 HTTP Response
Larapi::methodNotAllowed();     // 405 HTTP Response
Larapi::conflict();             // 409 HTTP Response
Larapi::unprocessableEntity();  // 422 HTTP Response
Larapi::internalError();		// 500 HTTP Response
Larapi::notImplemented();       // 501 HTTP Response
Larapi::notAvailable();         // 503 HTTP Response
```

**Example: Return HTTP Bad Request**

This:

```
// app/Http/routes.php

Route::get('/', function()
{
	return Larapi::badRequest();
});
```

will return:

```
{
	"success": false
}
```

with these headers:

```
HTTP/1.1 400 Bad Request
Content-Type: application/json

```

**Example: Return HTTP Bad Request with Custom Application Error Message**

This:

```
// app/Http/routes.php

Route::get('/', function()
{
	$errorCode = 4001;
	$errorMessage = 'Invalid email address.';

	return Larapi::badRequest($errorMessage, $errorCode);
});
```

will return:

```
{
	"success": false,
	"error_code": 4001,
	"error": "Invalid email address."
}
```

with these headers:

```
HTTP/1.1 400 Bad Request
Content-Type: application/json

```

**Example: Return HTTP Bad Request with An Array of Errors and Custom Response Headers**

This:

```
// app/Http/routes.php

Route::get('/', function()
{
	$errorCode = 4001;
	$errors = [
		'email' => 'Invalid email address',
		'password' => 'Not enough characters',
	];

	$headers = [
		'Header-1' => 'Header-1 Data',
		'Header-2' => 'Header-2 Data'
	];

	return Larapi::badRequest($errors, null, $headers);
});
```

will return:

```
{
	"success": false,
	"errors": {
		"email": "Invalid email address",
		"password": "Not enough characters"
	}
}
```

with these headers:

```
HTTP/1.1 200 OK
Content-Type: application/json
Header-1: Header-1 Data
Header-2: Header-2 Data

```

License
-------

[](#license)

Larapi is licensed under the terms of the [MIT License](LICENSE).

TODO
----

[](#todo)

- test, test, test

###  Health Score

33

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity24

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity65

Established project with proven stability

 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

Every ~45 days

Recently: every ~112 days

Total

11

Last Release

3438d ago

Major Versions

1.2 → 2.02016-01-04

2.1 → 3.02016-12-26

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/7908386?v=4)[Nick Law](/maintainers/nicklaw5)[@nicklaw5](https://github.com/nicklaw5)

---

Top Contributors

[![nicklaw5](https://avatars.githubusercontent.com/u/7908386?v=4)](https://github.com/nicklaw5 "nicklaw5 (34 commits)")

---

Tags

laravelphp-laravelresponsejsonapilaravel

### Embed Badge

![Health badge](/badges/nicklaw5-larapi/health.svg)

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

###  Alternatives

[obiefy/api-response

Simple Laravel package to return Json responses.

17325.0k](/packages/obiefy-api-response)[nilportugues/laravel5-json-api-dingo

Laravel5 JSONAPI and Dingo together to build APIs fast

311.5k](/packages/nilportugues-laravel5-json-api-dingo)[nilportugues/laravel5-haljson

Laravel 5 HAL+JSON API Transformer Package

151.0k](/packages/nilportugues-laravel5-haljson)

PHPackages © 2026

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