felixdorn / apiresponse
This package is abandoned and no longer maintained.
No replacement package was suggested.
A wrapper to psr-7 response for api
1.0.0
2019-06-23 16:41 UTC
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