To make a HTTP request with a custom method in Go, you can use the http.NewRequest()
function along with the method name you want to use. Here's an example:
main.go445 chars24 lines
In the example above, we create a new http.Request
with the method name "CUSTOM" and the URL "https://example.com". We also provide a request body using a strings.Reader
.
Next, we use the http.Client
to make the request and retrieve the response. Finally, we close the response body to prevent resource leaks.
You can replace "CUSTOM" with any other HTTP method name you want to use, such as "PATCH", "PUT", or "DELETE".
gistlibby LogSnag