1. Go to this page and download the library: Download juststeveking/http-slim 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/ */
juststeveking / http-slim example snippets
declare(strict_types=1);
use JustSteveKing\HttpSlim\HttpClient;
use Symfony\Component\HttpClient\Psr18Client;
// Injecting Clients:
$httpClient = HttpClient::build(
clientInterface: new Psr18Client(),
requestFactory: new Psr18Client(),
streamFactory: new Psr18Client(),
);
// Using HTTP Auto-discovery
$httpClient = HttpClient::build();
// perform a get request
$httpClient->get(
uri: 'https://api.example.com/v1/resource',
);
// perform a post request
$httpClient->post(
uri: 'https://api.example.com/v1/resource',
body: ['foo' => 'bar'],
);
// perform a put request
$httpClient->put(
uri: 'https://api.example.com/v1/resource/identifier',
body: ['foo' => 'bar'],
);
// perform a patch request
$httpClient->patch(
uri: 'https://api.example.com/v1/resource/identifier',
body: ['foo' => 'bar'],
);
// perform a delete request
$httpClient->delete(
uri: 'https://api.example.com/v1/resource/identifier',
);
// perform an options request
$httpClient->options(
uri: 'https://api.example.com/v1/resource/identifier',
headers: ['X-OPTIONAL' => 'headers'],
);
// Adding Plugins
$httpClient->addPlugin(
plugin: new \Http\Client\Common\Plugin\HeaderDefaultsPlugin(
headers: ['Content-Type' => 'application/json'],
),
);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.