Skip to content
Laravel Packagev6.xMIT License0+ downloads

API Response: One envelope for every API response

API Response gives every API response the same shape. Return Response::success($posts) from a controller and get your data, API resources and paginators in one predictable envelope, with stable error codes, structured notifications, request IDs and opt-in JSON exceptions. Responses you build without it are left alone.

$composer require pharaonic/laravel-api-response

Compatibility

Each line is released for the versions in its row, read from that release's composer.json. Pick the line that matches your project; a combination not listed isn't supported. Find the right line of every package for your project.

LineLatest releasePHPLaravelStatusDocs
v6.xv6.0.0 Nov 25, 20268.06CurrentLaravel 6 no longer gets security fixes Docs: Read the v6.x docs

Maintenance

Latest release
v6.0.0
Nov 25, 2026 (11 hours ago)
Released lines
1
documented lines with a release; see compatibility
CI on 6.x
Tests passed
latest run Nov 25, 2026

From the package's releases and its GitHub Actions. A passing run means the test suite passed on 6.x, on every PHP version it supports; it isn't a security review, and each release line has its own runs on GitHub. Checked hourly.

A quick look

A paginated resource collection with a message, metadata and a notification.

app/Http/Controllers/PostController.php
1use App\Http\Resources\PostResource;
2use App\Post;
3use Pharaonic\Laravel\ApiResponse\Response;
4 
5public function index()
6{
7 return Response::success(PostResource::collection(Post::query()->paginate(15)))
8 ->message('Posts retrieved successfully.')
9 ->meta('version', '1.0')
10 ->notify('Posts loaded.', 'success')
11 ->withQueryString(['search', 'sort']);
12}
Key Features

Everything an API response needs

Return a builder from your controller; Laravel turns it into the response.

One Envelope

success, message, code, data, errors and meta, with unset fields left out and your own null, [] or 0 always kept.

Every Paginator

Length-aware, simple and cursor paginators become their items plus meta.pagination, without invented totals.

API Resources

JsonResource and resource collections resolve with the current request, keeping conditional fields, with() and additional().

JSON Exceptions

An opt-in renderer maps validation, auth, 404, throttling and your own exceptions, keeps headers, and hides 5xx details.

Profiles

Rename fields, reshape pagination or drop the envelope per route, per response, or by Accept media type.

Request IDs

A middleware sends a safe request ID in a header and the body, and adds it to your log records.

FAQ

API Response Questions

Quick answers about installing and using API Response.

What is API Response?

One consistent JSON envelope for Laravel API responses. Data, errors, API resources and every paginator, with profiles, structured notifications, request IDs and opt-in exception rendering. It's a free, open-source Laravel package by Pharaonic.

How do I install API Response?

Run composer require pharaonic/laravel-api-response in your project's root directory.

What does API Response require?

The latest release requires PHP 8.0 and Laravel 6.

Does it change responses I already return?

No. Only responses you build with this package's Response class are shaped. Exception rendering is off until you register ExceptionRenderer with your exception handler, and even then it only handles API requests.

Does it need pharaonic/laravel-seo?

No. The SEO integration is optional, and a response carries SEO tags only when it calls withSEO().

Can I change the shape of the JSON?

Yes. Rename any envelope field in the configuration, or register a profile that reshapes pagination and notifications, adds headers, or sends the data without an envelope.

Is API Response free to use?

Yes. API Response is open source under the MIT license, so you can use it in personal and commercial projects.

Where can I find the API Response documentation?

Read the API Response documentation for setup, configuration, and usage examples.

How do I report a bug or contribute to API Response?

Open an issue or a pull request on GitHub, ask in GitHub Discussions, or chat with us on Discord.

Ready to dig in?

Read the full documentation for installation, configuration, status helpers, pagination and query strings, API resources, profiles and content negotiation, notifications, SEO, request IDs, exception rendering and extending the builder.