PHPackages                             multividas/api-responser - 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. multividas/api-responser

ActivePackage[API Development](/categories/api)

multividas/api-responser
========================

Composer package to facilitates the process of structuring and generating API responses

v2024.07.01.22.19(1y ago)15381MITPHPPHP ^8.2

Since May 25Pushed 1y ago1 watchersCompare

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

READMEChangelog (2)Dependencies (5)Versions (5)Used By (0)

[![API Responser package logo](./assets/api-responser.svg)](./assets/api-responser.svg)API Responser
=============

[](#api-responser)

[![Tests](https://github.com/multividas/api-responser/actions/workflows/tests.yml/badge.svg)](https://github.com/multividas/api-responser/actions/workflows/tests.yml)[![Total Downloads](https://camo.githubusercontent.com/4c67c0e2d28b361fd25fa8f6c775f90d440211c41697076b99e1b3a47277d686/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d756c746976696461732f6170692d726573706f6e7365722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/multividas/api-responser)[![License](https://camo.githubusercontent.com/e63b590df854966c567ec1546977460c758c1633db5e1660e217b0a3366f8a0c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6d756c746976696461732f6170692d726573706f6e7365723f7374796c653d666c61742d737175617265)](https://github.com/multividas/api-responser/blob/main/LICENSE)

Composer package to facilitates the process of structuring and generating API responses

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

[](#installation)

Require this package with composer.

```
composer require multividas/api-responser
```

ServiceProvider:
----------------

[](#serviceprovider)

**\[Optional\]** Adding the **ApiResponserServiceProvider** to the providers array in **config/app.php**

```
\Multividas\ApiResponser\Providers\ApiResponserServiceProvider::class,
```

**\[Optional\]** To get **X-Application-Name** http response header, Copy the package config to your local config with the publish command:

```
php artisan vendor:publish --tag=api-responser-config
```

Usage
-----

[](#usage)

```
use \Multividas\ApiResponser\Traits\ApiResponser;

class Controller extends BaseController
{
    use ApiResponser;
}
```

### ApiResponser Interface

[](#apiresponser-interface)

Using the `ApiResponser` interface methods.

- `showAll()` method receives **`Collection|JsonResource`** as its param.
- `showOne()` method receives **`Model|JsonResource $instance`** as its param.

```
use \Multividas\ApiResponser\Interfaces\ApiRepositoryInterface;

class PostsController extends Controller
{
    public function __construct(
        public ApiRepositoryInterface $apiRepository
    ) {
    }

    public function index(): JsonResponse
    {
        return $this->apiRepository->showAll(Post::all());
    }

    public function show(Post $post): JsonResponse
    {
        if (!$post instanceof Post) {
            return $this->infoResponse('Item Not Found', 404, []);
        }

        return $this->apiRepository->showOne($post);
    }
}
```

### ApiResponser Facade

[](#apiresponser-facade)

Using the `ApiResponser` facade design pattern.

```
use Multividas\ApiResponser\Facades\ApiResponser;

class PostsController extends Controller
{
    public function index(): JsonResponse
    {
        return ApiResponser::showAll(Post::all());
    }

    public function show(string $postId): JsonResponse
    {
        $post = Post::find($postId);

        if (!$post instanceof Post) {
            return $this->infoResponse('Post Not Found', 404, (object)[]);
        }

        return ApiResponser::showOne($post);
    }
}
```

This approach provides a cleaner and more organized way to interact with the `ApiRepositoryInterface` instance in your controller methods.

### Success Response

[](#success-response)

Successful response containing the requested data and an appropriate status code.

```
{
    "data": [],
    "code": 200,
    "meta": {}
}
```

Learn more: [Multividas API Responser](https://developers.multividas.com/rest/introduction/api-responser)

---

### Run PHPUnit tests

[](#run-phpunit-tests)

```
composer test
```

🤝 Contributing
--------------

[](#-contributing)

Please read the [contributing guide](https://github.com/multividas/.github/blob/main/CONTRIBUTING.md).

🛡️ Security Issues
------------------

[](#️-security-issues)

If you discover a security vulnerability within Multividas, we would appreciate your help in disclosing it to us responsibly, please check out our [security issues guidelines](https://github.com/multividas/.github/blob/main/SECURITY.md).

🛡️ License
----------

[](#️-license)

Licensed under the [MIT license](https://github.com/multividas/.github/blob/main/LICENSE).

---

> Email:

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance34

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 50% 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 ~19 days

Total

3

Last Release

686d ago

Major Versions

v1.0.0 → v2024.07.01.22.112024-07-01

### Community

Maintainers

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

---

Top Contributors

[![soulaimaneyahya](https://avatars.githubusercontent.com/u/75973907?v=4)](https://github.com/soulaimaneyahya "soulaimaneyahya (2 commits)")[![xtxt22](https://avatars.githubusercontent.com/u/173807917?v=4)](https://github.com/xtxt22 "xtxt22 (2 commits)")

---

Tags

api-responsermultividasapi-responser

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/multividas-api-responser/health.svg)

```
[![Health](https://phpackages.com/badges/multividas-api-responser/health.svg)](https://phpackages.com/packages/multividas-api-responser)
```

###  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)
