2017 © Pedro Peláez
 

library net-call

Easy to use and mockable HTTP client, wraps most common http calls functionality around Guzzle.

image

denismitr/net-call

Easy to use and mockable HTTP client, wraps most common http calls functionality around Guzzle.

  • Saturday, January 20, 2018
  • by denismitr
  • Repository
  • 1 Watchers
  • 3 Stars
  • 21 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 163 % Grown

The README.md

NetCall

NetCall is a convenient and easy to use HTTP client. It is a wrapper around Guzzle, made for most common use cases. And is designed to make development and testing easier and more pleasant., (*1)

Author

Denis Mitrofanov, (*2)

Installation

composer require denismitr/net-call

Usage

$response = NetCall::new()->get('http://www.google.com?foo=bar');

// NetCallResponseInterface methods
$response->body(); // : string
$response->json(); // : array
$response->header('some-key');
$response->headers(); // : array
$response->status(); // : int
$response->isSuccess(); // : bool
$response->isOk(); // : bool
$response->isRedirect(); // : bool
$response->isServerError(); // : bool

```php // request params will be json encoded by default $response = NetCall::new()->post('http://test.com/post', [ 'foo' => 'bar', 'baz' => 'qux', ]);, (*3)

$response->json(); // array with json response data, (*4)


From Params ```php $response = NetCall::new()->asFormData()->post('http://myurl.com/post', [ 'foo' => 'bar', 'baz' => 'qux', ]);

Multipart, (*5)

$response = NetCall::new()->asMultipart()->post('http://myurl.com/multi-part', [
    [
        'name' => 'foo',
        'contents' => 'bar'
    ],
    [
        'name' => 'baz',
        'contents' => 'qux',
    ],
    [
        'name' => 'test-file',
        'contents' => 'test contents',
        'filename' => 'test-file.txt',
    ],
]);

With Headers, (*6)

$response = NetCall::new()
    ->withHeaders(['Custom' => 'Header'])
    ->get('http://myurl.com/get');

Set Accept header, (*7)

$response = NetCall::new()
    ->accept('application/json')
    ->post('http://myurl.com/post');

Patch requests are supported, (*8)

$response = NetCall::new()->patch('http://myurl.com/patch', [
    'foo' => 'bar',
    'baz' => 'qux',
]);

Exceptions

Exceptions are not thrown on 4xx and 5xx: use response status method instead., (*9)

Redirects

Redirects are followed by default, (*10)

To disable that:, (*11)

$response = NetCall::new()->noRedirects()->get('http://myurl.com/get');

$response->status(); // 302
$response->header('Location'); // http://myurl.com/redirected

Auth

Basic auth, (*12)

$response = NetCall::new()
    ->withBasicAuth('username', 'password')
    ->get('http://myurl.com/basic-auth');

Digest auth, (*13)

$response = NetCall::new()
    ->withDigestAuth('username', 'password')
    ->get('http://myurl.com/digest-auth');

Timeout

Set timeout, (*14)

NetCall::new()->timeout(1)->get('http://myurl.com/timeout');

// If more then a second passes
// \Denismitr\NetCall\Exceptions\NetCallException is thrown

The Versions

20/01 2018

dev-master

9999999-dev

Easy to use and mockable HTTP client, wraps most common http calls functionality around Guzzle.

  Sources   Download

MIT

The Requires

 

The Development Requires

http request client guzzle

20/01 2018

0.1.x-dev

0.1.9999999.9999999-dev

Easy to use and mockable HTTP client, wraps most common http calls functionality around Guzzle.

  Sources   Download

MIT

The Requires

 

The Development Requires

http request client guzzle

20/01 2018

v0.1

0.1.0.0

Easy to use and mockable HTTP client, wraps most common http calls functionality around Guzzle.

  Sources   Download

MIT

The Requires

 

The Development Requires

http request client guzzle