felixdorn / apiresponse
A wrapper to psr-7 response for api
Installs: 114
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/felixdorn/apiresponse
Requires
- ext-json: *
- guzzlehttp/psr7: ^1.5
- http-interop/response-sender: ^1.0
- kayex/http-codes: ^1.1
- lukasoppermann/http-status: ^2.0
- psr/http-message: ^1.0
Requires (Dev)
- phpunit/phpunit: ^7.5
This package is auto-updated.
Last update: 2020-03-07 07:53:55 UTC
README
A wrapper to psr-7 response for api
composer require felixdorn/apiresponse
<?php use Felix\Response\ApiResponse; use function Http\Response\send; $response = (new ApiResponse()) ->setStatusCode(200) ->setBody(['foo' => 'bar']) ->setHeaders(['Foo' => 'Bar']) ->build(); send($response);
A method named setProtocol() can be used if you want to change the HTTP version
build() returns a standardized psr-7 ResponseInterface with the content defined.
The output look like this
{
"status": "sucess",
"code": 200,
"description": "OK",
"data": {
"foo": "bar"
}
}
Tests
Fully tested