PHPackages                             thuraaung2493/laravel-api-utils - 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. thuraaung2493/laravel-api-utils

ActiveLibrary[API Development](/categories/api)

thuraaung2493/laravel-api-utils
===============================

Laravel API Utilities.

0.2.1(2y ago)05MITPHPPHP ^8.2

Since Oct 23Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/thuraaung2493/laravel-api-utils)[ Packagist](https://packagist.org/packages/thuraaung2493/laravel-api-utils)[ RSS](/packages/thuraaung2493-laravel-api-utils/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (7)Versions (5)Used By (0)

Laravel API Utils
=================

[](#laravel-api-utils)

**It supports *Laravel 9+* and *PHP 8.2*+**

- [Laravel API Utils](#laravel-api-utils)
    - [Description](#description)
    - [Installation](#installation)
    - [Publish the config file](#publish-the-config-file)
    - [Usage](#usage)
        - [Responses](#responses)
            - [API Success JSON Response Format.](#api-success-json-response-format)
            - [API Paginated JSON Response Format.](#api-paginated-json-response-format)
            - [A JSON Response Format for API Errors.](#a-json-response-format-for-api-errors)
            - [A JSON Response Format for API Messages Only](#a-json-response-format-for-api-messages-only)
        - [Enums](#enums)
        - [Headers](#headers)
        - [Middleware Classes](#middleware-classes)
        - [Exceptions](#exceptions)

Description
-----------

[](#description)

This package contains many utility APIs that assist in API creation.

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

[](#installation)

Require this package with composer using the following command:

```
composer require thuraaung2493/laravel-api-utils
```

Publish the config file
-----------------------

[](#publish-the-config-file)

```
php artisan vendor:publish --provider="Thuraaung\APIUtils\LaravelAPIUtilsServiceProvider" --tag="api-utils"
```

Usage
-----

[](#usage)

### Responses

[](#responses)

**All API Response classes implement the Responsable interface.**

ClassDescriptionThuraaung\\APIUtils\\Http\\Responses\\API\\SuccessResponse::classIt returns json response for success.Thuraaung\\APIUtils\\Http\\Responses\\API\\PaginatedResponse::classIt returns json response for pagination.Thuraaung\\APIUtils\\Http\\Responses\\API\\FailResponse::classIt returns json response for fail.Thuraaung\\APIUtils\\Http\\Responses\\API\\MessageOnlyResponse::classIt returns json response for message-only.Thuraaung\\APIUtils\\Http\\Responses\\API\\Response::classAPI Utils Responses Class.```
  use Thuraaung\APIUtils\Http\Responses\API\SuccessResponse;
  use Thuraaung\APIUtils\Http\Responses\API\PaginatedResponse;
  use Thuraaung\APIUtils\Http\Responses\API\FailResponse;
  use Thuraaung\APIUtils\Http\Responses\API\MessageOnlyResponse;
  use Thuraaung\APIUtils\Http\Responses\API\Response;

  // API Success Response with resource data.
  return new SuccessResponse($userResource); // OR
  return Response::of()->sendSuccess($userResource);

  // API Success Response with resource data.
  return new PaginatedResponse($userPaginationResource); // OR
  return Response::of()->paginated($userPaginationResource);

  // API Fail Response with errors.
  return new FailResponse(errors: ['email' => 'Email is invalid.']); // OR
  return Response::of()->sendFail(['email' => 'Email is invalid.']);

  // API Message-Only Response.
  return new MessageOnlyResponse('Login successful.', Status::OK); // OR
  return Response::of()
    ->status(Status::OK)
    ->sendMessage('Login successful.')
```

#### API Success JSON Response Format.

[](#api-success-json-response-format)

```
{
    "data": "resource",
    "message": "Success.",
    "status": 200
}
```

#### API Paginated JSON Response Format.

[](#api-paginated-json-response-format)

```
{
    "data": "resource",
    "links": {},
    "meta": {},
    "message": "Success.",
    "status": 200
}
```

#### A JSON Response Format for API Errors.

[](#a-json-response-format-for-api-errors)

```
{
    "title": "Failed!",
    "message": "Something went wrong!",
    "errors": [],
    "status": 500
}
```

#### A JSON Response Format for API Messages Only

[](#a-json-response-format-for-api-messages-only)

```
{
    "message": "Success",
    "status": 500
}
```

### Enums

[](#enums)

ClassDescriptionThuraaung\\APIUtils\\Http\\Responses\\Status::classHTTP Status.Thuraaung\\APIUtils\\Http\\Method::classRequest Methods.Thuraaung\\APIUtils\\Http\\Scheme::classScheme.Thuraaung\\APIUtils\\Http\\Headers\\Connection::classConnection Headers.Thuraaung\\APIUtils\\Http\\Headers\\ContentEncoding::classContent Encoding Headers.Thuraaung\\APIUtils\\Http\\Headers\\ContentType::classContent Type Headers.### Headers

[](#headers)

```
    use Thuraaung\APIUtils\Http\Headers\Headers;
    use Thuraaung\APIUtils\Http\Headers\ContentType;
    use Thuraaung\APIUtils\Http\Headers\ContentEncoding;

    // Create headers with pre defined in config.
    Headers::default();
    // Transform array
    Headers::default()->toArray();

    // Other utils methods
    Headers::of()
        ->accept(ContentType::JSON)
        ->contentType(ContentType::JSON)
        ->acceptEncoding(ContentEncoding::GZIP)
        ->contentEncoding(ContentEncoding::GZIP, vapor: false)
        ->contentLength(214)
        ->toArray();
```

### Middleware Classes

[](#middleware-classes)

ClassDescriptionThuraaung\\APIUtils\\Http\\Middleware\\GzipEncodingResponse::classIt is used to apply Gzip encoding to API responses.Thuraaung\\APIUtils\\Http\\Middleware\\JsonAPIResponse::classIt is used to apply default headers to API responses.### Exceptions

[](#exceptions)

ClassDescriptionThuraaung\\APIUtils\\Exceptions\\APIExceptionsHandler::classIt is used to handle API exceptions.Thuraaung\\APIUtils\\Exceptions\\Concerns\\HasRender::classIt is trait that used to custom exceptions for API response.> App\\Exceptions\\Handler.php

```
    use Thuraaung\APIUtils\Exceptions\APIExceptionsHandler;

    class Handler extends APIExceptionsHandler
    {
        // others

        public function register(): void
        {
            $this->handleAuthenticationException()
                ->handleAccessDeniedException()
                ->handleNotFoundException()
                ->handleMethodNotAllowException()
                ->handleNotAcceptableException()
                ->handleUnprocessableEntityException()
                ->handleTooManyRequestsException()
                ->handleMergeExceptions([]);
        }

        protected function isJsonRequest(): bool
        {
            return \request()->isJson() && \request()->is('api/*');
        }
    }
```

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance57

Moderate activity, may be stable

Popularity4

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 65.2% 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 ~40 days

Total

3

Last Release

853d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6764acf86f328588b8b35a2e03683a19f42ed37d11dddb582256743c467d318f?d=identicon)[thuraaung2493](/maintainers/thuraaung2493)

---

Top Contributors

[![thuraaung2493](https://avatars.githubusercontent.com/u/22706964?v=4)](https://github.com/thuraaung2493 "thuraaung2493 (15 commits)")[![thura-solinxtechnology](https://avatars.githubusercontent.com/u/124573470?v=4)](https://github.com/thura-solinxtechnology "thura-solinxtechnology (8 commits)")

---

Tags

apilaravelutilities

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/thuraaung2493-laravel-api-utils/health.svg)

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

###  Alternatives

[nuwave/lighthouse

A framework for serving GraphQL from Laravel

3.5k10.7M93](/packages/nuwave-lighthouse)[mollie/laravel-mollie

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

3624.1M28](/packages/mollie-laravel-mollie)[mll-lab/laravel-graphiql

Easily integrate GraphiQL into your Laravel project

683.2M9](/packages/mll-lab-laravel-graphiql)[worksome/graphlint

A static analysis tool for GraphQL

13189.4k](/packages/worksome-graphlint)[esign/laravel-conversions-api

A laravel wrapper package around the Facebook Conversions API

69145.4k](/packages/esign-laravel-conversions-api)[didww/didww-api-3-php-sdk

PHP SDK for DIDWW API 3

1218.2k](/packages/didww-didww-api-3-php-sdk)

PHPackages © 2026

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