feat: add support for OPTIONS requests (#13)

* feat: add support for OPTIONS requests

* feat(doc): add OPTIONS ref. to README
This commit is contained in:
Victor Westerlund 2024-04-06 14:55:04 +00:00 committed by GitHub
parent 1ed38a8c3d
commit 89a8c04104
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 20 additions and 1 deletions

View file

@ -137,3 +137,19 @@ Example:
```php
$client->call("my/endpoint")->params(["foo" => "bar"])->delete();
```
### `OPTIONS` Request
Make an `OPTIONS` request by chaining `options()` at the end of a method chain. This method will return a `Reflect\Response` object.
Use this method to query Reflect for available request methods.
```php
Client->options(): Reflect\Response;
```
Example:
```php
$client->call("my/endpoint"))->options();
```

View file

@ -42,7 +42,6 @@
$this->headers["Authorization"] = "Bearer {$this->key}";
}
// Construct HTTP headers string from array
$headers = array_map(fn(string $k, string $v): string => "{$k}: {$v}\r\n", array_keys($this->headers), array_values($this->headers));
return implode("", $headers);
@ -137,4 +136,8 @@
$this->set_request_body($payload);
return new Response(...$this->http_call(Method::DELETE));
}
public function options(): Response {
return new Response(...$this->http_call(Method::OPTIONS));
}
}