PHP code example of denismitr / net-call

1. Go to this page and download the library: Download denismitr/net-call library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

denismitr / net-call example snippets


$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

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

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

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

$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',
    ],
]);

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

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

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

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

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

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

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

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

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