From 89a8c041044c8c60cefafc4716d5d61b96c43e06 Mon Sep 17 00:00:00 2001 From: Victor Westerlund Date: Sat, 6 Apr 2024 14:55:04 +0000 Subject: [PATCH] feat: add support for `OPTIONS` requests (#13) * feat: add support for OPTIONS requests * feat(doc): add OPTIONS ref. to README --- README.md | 16 ++++++++++++++++ src/Reflect/Client.php | 5 ++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 376af5a..498dc77 100644 --- a/README.md +++ b/README.md @@ -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(); +``` diff --git a/src/Reflect/Client.php b/src/Reflect/Client.php index 2ea09e2..c7acbff 100644 --- a/src/Reflect/Client.php +++ b/src/Reflect/Client.php @@ -41,7 +41,6 @@ if ($this->key) { $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)); @@ -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)); + } }