PHP code example of soltancode / send-request

1. Go to this page and download the library: Download soltancode/send-request 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/ */

    

soltancode / send-request example snippets


use Soltancode\SendRequest\Facades\SendRequest;

// $baseUrl = "https://dummyjson.com";
// $service = "/products/1";

# Using as class:
SendRequest::get($baseUrl, $service);

# Using as helper:
sendRequest()->get($baseUrl, $service)

// $baseUrl = "https://dummyjson.com";
// $service = "/products/1";
// $params  = [
//     'q' => 'phone'
// ];

# Using as class:
SendRequest::get($baseUrl, $service, $params); # https://dummyjson.com/products/search?q=phone

# Using as helper:
sendRequest()->get($baseUrl, $service, $params); # https://dummyjson.com/products/search?q=phone

// $baseUrl = "https://api.example.com";
// $service = "/login";

# Using as class:
SendRequest::post($baseUrl, $service, [
    'username' => 'myusername',
    'password' => 'mypassword'
]);

# Using as helper:
sendRequest()->post($baseUrl, $service, [
    'username' => 'myusername',
    'password' => 'mypassword'
]);

// $baseUrl = "https://api.example.com";
// $service = "/users/1";

# Using as class:
SendRequest::put($baseUrl, $service, [
    'first_name' => 'John',
    'last_name' => 'Doe'
]);

# Using as helper:
sendRequest()->put($baseUrl, $service, [
    'first_name' => 'John',
    'last_name' => 'Doe'
]);

// $baseUrl = "https://api.example.com";
// $service = "/users/1";

# Using as class:
SendRequest::patch($baseUrl, $service, [
    'first_name' => 'John'
]);

# Using as helper:
sendRequest()->patch($baseUrl, $service, [
    'first_name' => 'John'
]);

// $baseUrl = "https://api.example.com";
// $service = "/users";

# Using as class:
SendRequest::delete($baseUrl, $service, [
    'id' => 'John'
]);

# Using as helper:
sendRequest()->delete($baseUrl, $service, [
    'id' => 'John'
]);

$response = sendRequest()->timeout(3)->post(/* ... */);