Introduction - matical/nana GitHub Wiki

This documentation is a WIP.

Quick Start

use ksmz\nana\Nana;

$response = Nana::get('https://httpbin.org/get');

$response->status(); // 200
$response->json()->url; // "https://httpbin.org/get"

Consume

Consume is wrapper around Guzzle/PSR-7's Response. It provides a slightly terser syntax for many common tasks when interacting with APIs.

You can also access the underlying raw response instance by calling the methods directly. All calls made to automatically passed directly to Response. Checkout Guzzle's documentation for the supported methods.

# Headers
$response->header('server'); // "nginx" (Comma separated, as per RFC spec)
$response->header('server', $asArray = true); // ["nginx"] (Comma delimited values are exploded)
$response->headers(); // All available headers, wrapped in an array.

# Body
$response->body(); // <Raw body data>
(string) $response; // ditto
$response->json($asArray = false); // json_decode()'d body

# Statuses, returns bools
$response->isOk() // >= 200, <300
$response->isRedirection() // >= 300, <400
$response->isClientError() // >= 400, <500
$response->isServerError() // >= 500

# Stream
$response->stream(); // Instance of \GuzzleHttp\Psr7\Stream

# Guzzle Response
$response->getHeaderLine('Date'); // All calls are proxied to the underlying PSR-7/Guzzle Response instance

New Instances

There are 3 main ways to make a request. Choosing which method to use depends on when you wish to configure your clients.

Regardless of which method you're picking, all calls will always return a new instance of Consume.

with Static Proxy

use ksmz\nana\Nana;

$json = Nana::withHeaders(['Authorization' => "Bearer $secret"])
            ->get('https://httpbin.org/get')
            ->json();

new

use ksmz\nana\Fetch;

$http = new Fetch(['base_uri' => 'https://httpbin.org']);
$json = $http->get('/get')
             ->json();

Sinks

See Sink

Output

{
  "args": {},
  "headers": {
    "Accept": "application/json",
    "Connection": "close",
    "Host": "httpbin.org",
    "User-Agent": "nana/0.1",
  },
  "origin": "x.x.x.x",
  "url": "https://httpbin.org/get",
}
⚠️ **GitHub.com Fallback** ⚠️