Download the PHP package ayd/api-response-hyperf without Composer
On this page you can find all versions of the php package ayd/api-response-hyperf. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ayd/api-response-hyperf
More information about ayd/api-response-hyperf
Files in ayd/api-response-hyperf
Package api-response-hyperf
Short Description An API response package for hyperf applications at AYD Company.
License MIT
Informations about the package 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
The ConfigProvider is auto-discovered by Hyperf and registers ApiResponse as a dependency.
Usage
1. Dependency Injection
Inject ApiResponse into your controller or service. Call setResponse() with the Hyperf response object before use:
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):
Error Handling
Unlike the Laravel package, all methods return Psr\Http\Message\ResponseInterface — error methods do not throw exceptions. Always return the result:
Available error methods: fail(), error(), badRequest(), unauthorized(), forbidden(), notFound(), unprocessable().
Abilities Resolver
Bind your resolver in a ConfigProvider or dependency configuration:
Hyperf's DI container will auto-inject it into ApiResponse's constructor.
API Reference
Success Methods
| Method | HTTP Status | Return 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
| Method | HTTP Status | Return 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
- PHP ^8.1
ayd/api-response-base^1.0hyperf/http-server^3.0psr/http-message^1.0 | ^2.0
License
MIT
All versions of api-response-hyperf with dependencies
ayd/api-response-base Version ^1.0
hyperf/http-server Version ^3.0
psr/http-message Version ^1.0|^2.0