use RequestBack\Request; $request = new Request(); $response = $request->get('https://api.example.com/data'); if ($response->status() == 200) { // Successful response, process data $data = $response->body(); // ... } else { // Error occurred, handle appropriately $error = $response->error(); // ... }
use RequestBack\Request; use RequestBack\RequestOptions; $request = new Request(); $options = new RequestOptions([ 'json' => [ 'name' => 'John', 'age' => 30 ] ]); $response = $request->post('https://api.example.com/data', $options); if ($response->status() == 200) { // Successful response, process data $data = $response->json(); // ... } else { // Error occurred, handle appropriately $error = $response->error(); // ... }In this example, we create a new `RequestOptions` object with a JSON payload, and pass it as an argument to the `post()` method. We then retrieve the response as JSON data using the `json()` method. The PHP Request Back library can be found on GitHub under the namespace `RequestBack`.