Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide the response as an object #2

Closed
hollodotme opened this issue Feb 23, 2017 · 1 comment
Closed

Provide the response as an object #2

hollodotme opened this issue Feb 23, 2017 · 1 comment

Comments

@hollodotme
Copy link
Owner

hollodotme commented Feb 23, 2017

Currently the response is a plain string like this:

X-Script: worker.php
Content-type: text/html; charset=UTF-8

Hello World

For a better usage provide the response as an immutable object with the following interface:

<?php declare(strict_types=1);

interface ProvidesResponseData
{
    public function getRequestId() : int;

    public function getHeaders() : array;

    public function getHeader( string $headerKey ) : string;

    public function getBody() : string;

    public function getRawResponse() : string;

    public function getDuration() : float;
}

So headers and body as well as the raw response can be accessed separately.

For the example response above the usage would look like this:

<?php declare(strict_types=1);

$response = $client->sendRequest($params, $content);

echo $response->getRequestId();
/*
prints:

1234
*/

print_r($response->getHeaders());
/*
prints:

Array
(
    ['X-Custom'] => 'Header'
    ['Content-Type'] => 'text/plain; charset=UTF-8'
)
*/

echo $response->getHeader('X-Custom');
/*
prints:

Header
*/

echo $response->getHeader('Content-Type');
/*
prints:

text/plain; charset=UTF-8
*/

echo $response->getBody();
/*
prints:

Hello World
*/

echo $response->getRawResponse();
/*
prints:

X-Script: worker.php
Content-type: text/html; charset=UTF-8

Hello World
*/

echo $response->getDuration();
/*
prints:

0.54829836
*/
@hollodotme hollodotme added this to the v1.1.0 / v2.1.0 milestone Feb 23, 2017
@hollodotme hollodotme self-assigned this Feb 23, 2017
@hollodotme
Copy link
Owner Author

@sandrokeil

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant