make a http delete request in go

To make a HTTP delete request in Go, you can use the http package that comes with the standard library. Here's an example:

main.go
import (
    "bytes"
    "net/http"
)

func main() {
    url := "http://example.com/delete/something"
    req, err := http.NewRequest("DELETE", url, bytes.NewBuffer(nil))
    if err != nil {
        // handle error
    }

    resp, err := http.DefaultClient.Do(req)
    if err != nil {
        // handle error
    }

    // Use the response
}
343 chars
20 lines

In this example, we first create a http.NewRequest() representing the HTTP DELETE request. We then add any necessary headers or request parameters to the request (in this case, we add none and create an empty body bytes.NewBuffer(nil)).

Next, we use http.DefaultClient to send our request with http.DefaultClient.Do(). This returns a HTTP response object.

You can then use the http.Response object to get any information you need from the response or check for any errors that may have occurred.

related categories

gistlibby LogSnag