PHPackages                             ayd/api-response-hyperf - 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. ayd/api-response-hyperf

ActiveLibrary[API Development](/categories/api)

ayd/api-response-hyperf
=======================

An API response package for hyperf applications at AYD Company.

v1.0.0(yesterday)00MITPHPPHP ^8.1

Since Jun 18Pushed yesterdayCompare

[ Source](https://github.com/AYDcompany/api-response-hyperf)[ Packagist](https://packagist.org/packages/ayd/api-response-hyperf)[ RSS](/packages/ayd-api-response-hyperf/feed)WikiDiscussions master Synced today

READMEChangelog (1)Dependencies (3)Versions (2)Used By (0)

API Response Hyperf
===================

[](#api-response-hyperf)

Hyperf integration for the `ayd/api-response-base` package. Provides a service class and trait for building consistent JSON API responses with PSR-7 response objects.

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

[](#installation)

```
composer require ayd/api-response-hyperf
```

The `ConfigProvider` is auto-discovered by Hyperf and registers `ApiResponse` as a dependency.

Usage
-----

[](#usage)

### 1. Dependency Injection

[](#1-dependency-injection)

Inject `ApiResponse` into your controller or service. Call `setResponse()` with the Hyperf response object before use:

```
use Hyperf\HttpServer\Contract\ResponseInterface;
use Ayd\ApiResponseHyperf\ApiResponse;

class UserController
{
    public function __construct(
        private ApiResponse $response,
        private ResponseInterface $hyperfResponse,
    ) {
        $this->response->setResponse($this->hyperfResponse);
    }

    public function index()
    {
        return $this->response->success($users);
    }

    public function store()
    {
        // validation...

        return $this->response->created($user, 'User created');
    }

    public function show($id)
    {
        $user = User::find($id);

        if (!$user) {
            return $this->response->notFound('User not found');
        }

        return $this->response->success($user);
    }
}
```

### 2. Trait (for Controllers)

[](#2-trait-for-controllers)

Use `ApiResponseTrait` to call response methods directly. The trait expects the controller to have a `$this->response` property (the Hyperf `ResponseInterface`, which is auto-injected in Hyperf controllers):

```
use Ayd\ApiResponseHyperf\ApiResponseTrait;

class UserController
{
    use ApiResponseTrait;

    public function index()
    {
        return $this->success(User::all());
    }

    public function store()
    {
        // validation...

        return $this->created($user, 'User created');
    }

    public function destroy($id)
    {
        User::findOrFail($id)->delete();

        return $this->noContent();
    }
}
```

Error Handling
--------------

[](#error-handling)

Unlike the Laravel package, **all methods return `Psr\Http\Message\ResponseInterface`** — error methods do not throw exceptions. Always `return` the result:

```
public function show($id)
{
    $user = User::find($id);

    if (!$user) {
        return $this->notFound('User not found');
    }

    return $this->success($user);
}
```

Available error methods: `fail()`, `error()`, `badRequest()`, `unauthorized()`, `forbidden()`, `notFound()`, `unprocessable()`.

Abilities Resolver
------------------

[](#abilities-resolver)

Bind your resolver in a `ConfigProvider` or dependency configuration:

```
use Ayd\ApiResponseBase\Contracts\AbilitiesResolver;

return [
    'dependencies' => [
        AbilitiesResolver::class => MyAbilitiesResolver::class,
    ],
];
```

Hyperf's DI container will auto-inject it into `ApiResponse`'s constructor.

API Reference
-------------

[](#api-reference)

### Success Methods

[](#success-methods)

MethodHTTP StatusReturn Type`success($data, $message, $meta)`200`ResponseInterface``created($data, $message, $meta)`201`ResponseInterface``updated($data, $message, $meta)`200`ResponseInterface``accepted($data, $message, $meta)`202`ResponseInterface``noContent()`204`ResponseInterface`### Error Methods

[](#error-methods)

MethodHTTP StatusReturn Type`fail($code, $message, $data, $meta)`configurable`ResponseInterface``error($code, $message, $data, $meta)`configurable`ResponseInterface``badRequest($message, $data)`400`ResponseInterface``unauthorized($message)`401`ResponseInterface``forbidden($message)`403`ResponseInterface``notFound($message)`404`ResponseInterface``unprocessable($message, $data)`422`ResponseInterface`Requirements
------------

[](#requirements)

- PHP ^8.1
- `ayd/api-response-base` ^1.0
- `hyperf/http-server` ^3.0
- `psr/http-message` ^1.0 | ^2.0

License
-------

[](#license)

MIT

###  Health Score

39

—

LowBetter than 85% of packages

Maintenance100

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity42

Maturing project, gaining track record

 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

Unknown

Total

1

Last Release

1d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1c85593d180ab34bd56247c69debca02794f8f07b7ee0737fc897164858de6b1?d=identicon)[GeorgeKing](/maintainers/GeorgeKing)

---

Top Contributors

[![george-nbi-ad](https://avatars.githubusercontent.com/u/188939767?v=4)](https://github.com/george-nbi-ad "george-nbi-ad (2 commits)")

### Embed Badge

![Health badge](/badges/ayd-api-response-hyperf/health.svg)

```
[![Health](https://phpackages.com/badges/ayd-api-response-hyperf/health.svg)](https://phpackages.com/packages/ayd-api-response-hyperf)
```

###  Alternatives

[aws/aws-sdk-php

AWS SDK for PHP - Use Amazon Web Services in your PHP project

6.2k532.1M2.5k](/packages/aws-aws-sdk-php)[algolia/algoliasearch-client-php

API powering the features of Algolia.

69634.4M144](/packages/algolia-algoliasearch-client-php)[telnyx/telnyx-php

Official Telnyx PHP SDK — APIs for Voice, SMS, MMS, WhatsApp, Fax, SIP Trunking, Wireless IoT, Call Control, and more. Build global communications on Telnyx's private carrier-grade network.

35729.6k2](/packages/telnyx-telnyx-php)[neuron-core/neuron-ai

The PHP Agentic Framework.

1.9k496.1k33](/packages/neuron-core-neuron-ai)[n1ebieski/ksef-php-client

PHP API client that allows you to interact with the API Krajowego Systemu e-Faktur

8754.6k](/packages/n1ebieski-ksef-php-client)[trycourier/courier

Courier PHP SDK

15654.8k](/packages/trycourier-courier)

PHPackages © 2026

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