From 8b6117de12cc0a156aabe402bc072543fbb3734e Mon Sep 17 00:00:00 2001 From: Janos Pasztor Date: Mon, 26 Apr 2021 08:26:11 +0200 Subject: [PATCH] 1.1.0: Adding support for additional HTTP methods This release adds support for the Delete, Put, and Patch methods. --- CHANGELOG.md | 4 ++++ client.go | 24 ++++++++++++++++++++++++ client_impl.go | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 96f37f5..7897f44 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 1.1.0: Adding support for additional HTTP methods + +This release adds support for the Delete, Put, and Patch methods. + ## 1.0.2: Adding support for www-urlencoded request body This release adds the ability to switch request bodies to the `www-urlencoded` encoding for the purposes of OAuth2 authentication. diff --git a/client.go b/client.go index 5f470ff..4e6b448 100644 --- a/client.go +++ b/client.go @@ -24,4 +24,28 @@ type Client interface { requestBody interface{}, responseBody interface{}, ) (statusCode int, err error) + + // Put queries the configured endpoint with the path, sending the requestBody and providing the + // response in the responseBody structure. It returns the HTTP status code and any potential errors. + Put( + path string, + requestBody interface{}, + responseBody interface{}, + ) (statusCode int, err error) + + // Patch queries the configured endpoint with the path, sending the requestBody and providing the + // response in the responseBody structure. It returns the HTTP status code and any potential errors. + Patch( + path string, + requestBody interface{}, + responseBody interface{}, + ) (statusCode int, err error) + + // Delete queries the configured endpoint with the path, sending the requestBody and providing the + // response in the responseBody structure. It returns the HTTP status code and any potential errors. + Delete( + path string, + requestBody interface{}, + responseBody interface{}, + ) (statusCode int, err error) } diff --git a/client_impl.go b/client_impl.go index 1ff3a1b..382c312 100644 --- a/client_impl.go +++ b/client_impl.go @@ -20,6 +20,45 @@ type client struct { tlsConfig *tls.Config } +func (c *client) Put( + path string, + requestBody interface{}, + responseBody interface{}, +) (statusCode int, err error) { + return c.request( + http.MethodPut, + path, + requestBody, + responseBody, + ) +} + +func (c *client) Patch( + path string, + requestBody interface{}, + responseBody interface{}, +) (statusCode int, err error) { + return c.request( + http.MethodPatch, + path, + requestBody, + responseBody, + ) +} + +func (c *client) Delete( + path string, + requestBody interface{}, + responseBody interface{}, +) (statusCode int, err error) { + return c.request( + http.MethodDelete, + path, + requestBody, + responseBody, + ) +} + func (c *client) Request(Method string, path string, requestBody interface{}, responseBody interface{}) (statusCode int, err error) { return c.request( Method,