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

This package is auto-updated.

Last update: 2020-03-07 07:53:55 UTC


README

Build Status

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