Skip to content

Commit

Permalink
Update request.md
Browse files Browse the repository at this point in the history
  • Loading branch information
guibranco authored Oct 2, 2024
1 parent 0461a6f commit 6505df3
Showing 1 changed file with 75 additions and 13 deletions.
88 changes: 75 additions & 13 deletions docs/user-guide/request.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,14 @@
- [Available HTTP verbs](#available-http-verbs)
- [Get](#get)
- [Post](#post)
- [Post without payload](#post-without-payload)
- [Post with payload](#post-with-payload)
- [Put](#put)
- [Put without payload](#put-without-payload)
- [Put with payload](#put-with-payload)
- [Patch](#patch)
- [Patch without payload](#patch-without-payload)
- [Patch with payload](#patch-with-payload)
- [Delete](#delete)
- [Delete without payload](#delete-without-payload)
- [Delete with payload](#delete-with-payload)
Expand All @@ -20,7 +26,7 @@

## About

This class is responsible for doing [cURL](https://www.php.net/manual/en/book.curl.php) request with custom headers.
This class is responsible for doing [cURL](https://www.php.net/manual/en/book.curl.php) requests with custom headers.

## Requirements

Expand All @@ -30,7 +36,7 @@ This requires lib curl to be active with your PHP settings.

### Get

Performs HTTP GET request with custom headers.
Performs HTTP GET requests with custom headers.

```php

Expand All @@ -47,15 +53,34 @@ if ($response->statusCode >= 200 && $response->statusCode < 300) {

### Post

Performs HTTP POST request with custom headers.
#### Post without payload

Performs HTTP POST requests with custom headers.

```php

$headers = array("User-Agent: test/1.0", "Accept: application/json");
$payload = array("Foo" => "Bar");

$request = new Request();
$response = $request->post("http://example.com/", json_encode($payload), $headers);
$response = $request->post("https://example.com/", null, $headers);

if ($response->statusCode >= 200 && $response->statusCode < 300) {
echo $response->body;
}

```

#### Post with payload

Performs HTTP POST requests with custom headers and a payload.

```php

$headers = array("User-Agent: test/1.0", "Accept: application/json");
$payload = array("some" => "thing");

$request = new Request();
$response = $request->post("https://example.com/", json_encode($payload), $headers);

if ($response->statusCode >= 200 && $response->statusCode < 300) {
echo $response->body;
Expand All @@ -65,12 +90,31 @@ if ($response->statusCode >= 200 && $response->statusCode < 300) {

### Put

Performs HTTP PUT request with custom headers.
#### Put without payload

Performs HTTP PUT requests with custom headers.

```php

$headers = array("User-Agent: test/1.0", "Accept: application/json");

$request = new Request();
$response = $request->put("https://example.com/", null, $headers);

if ($response->statusCode >= 200 && $response->statusCode < 300) {
echo $response->body;
}

```

#### Put with payload

Performs HTTP PUT requests with custom headers and a payload.

```php

$headers = array("User-Agent: test/1.0", "Accept: application/json");
$payload = array("Foo" => "Rab");
$payload = array("some" => "thing");

$request = new Request();
$response = $request->put("https://example.com/", json_encode($payload), $headers);
Expand All @@ -83,10 +127,28 @@ if ($response->statusCode >= 200 && $response->statusCode < 300) {

### Patch

Performs HTTP PATCH request with custom headers.
#### Patch without payload

Performs HTTP PATCH requests with custom headers.

```php

$headers = array("User-Agent: test/1.0", "Accept: application/json");

$request = new Request();
$response = $request->patch("https://example.com/", null, $headers);

if ($response->statusCode >= 200 && $response->statusCode < 300) {
echo $response->body;
}

```

#### Patch with payload

Performs HTTP PATCH requests with custom headers and a payload.

```php

$headers = array("User-Agent: test/1.0", "Accept: application/json");
$payload = array("some" => "thing");
Expand All @@ -104,7 +166,7 @@ if ($response->statusCode >= 200 && $response->statusCode < 300) {

#### Delete without payload

Performs HTTP DELETE request with custom headers.
Performs HTTP DELETE requests with custom headers.

```php

Expand All @@ -121,7 +183,7 @@ if ($response->statusCode >= 200 && $response->statusCode < 300) {

#### Delete with payload

Performs HTTP DELETE request with custom headers and a payload.
Performs HTTP DELETE requests with custom headers and a payload.

```php

Expand All @@ -139,7 +201,7 @@ if ($response->statusCode >= 200 && $response->statusCode < 300) {

### Options

Performs HTTP OPTIONS request with custom headers.
Performs HTTP OPTIONS requests with custom headers.

```php

Expand All @@ -158,7 +220,7 @@ if ($response->statusCode >= 200 && $response->statusCode < 300) {

### Head

Performs HTTP HEAD request with custom headers.
Performs HTTP HEAD requests with custom headers.

```php

Expand All @@ -177,7 +239,7 @@ if ($response->statusCode >= 200 && $response->statusCode < 300) {

## Troubleshooting

If for some reason the request could not be completed, the result status code will be `-1` and an error property will be set with the content of `curl_error` response.
If the request could not be completed for some reason, the result status code will be `-1`, and an error property will be set with the content of the `curl_error` response.

```php

Expand Down

0 comments on commit 6505df3

Please sign in to comment.