$client = new GuzzleHttp\Client(); $response = $client->post('http://example.com/api/v1/create-user', [ 'body' => json_encode(['username' => 'john_doe', 'password' => 'p@ssw0rd']) ]); echo $response->getBody();
$client = new GuzzleHttp\Client(); $response = $client->post('http://example.com/api/v1/create-user', [ 'form_params' => [ 'username' => 'john_doe', 'password' => 'p@ssw0rd' ] ]); echo $response->getBody();In this example, GuzzleHttp is used to make a POST request to the API endpoint at http://example.com/api/v1/create-user. The form data is included in the request body as an array. The response from the API is then printed out to the screen. The package library used in these examples is GuzzleHttp.