A response builder for PSR.
This package includes different response builders based on the JSON response structure specified in JSON Data Errors Response (JDER). With the builders, various kinds of responses can be created easily instead of sending plain text responses.
Install this package as a dependency in the project:
composer require jder/psrTo create a JSON response, use the following code:
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Message\ResponseInterface as Response;
use Jder\Psr\Json\CreateJsonResponse;
function route(
Request $request,
Response $response,
): Response {
return CreateJsonResponse::success($response)->create();
}And the response will be shown as below:
{
"success": true,
"data": null,
"errors": []
}For the documentation,please refer to the documentation.
For contributing, please refer to the contributing guide.
This project is licensed under the terms of the MIT license.