-
-
Notifications
You must be signed in to change notification settings - Fork 772
Closed
Description
There are cases where we have to programmatically decide which http method to use when invoking an API. While we can create a map of handler functions to call the various put/post/get/delete/options functions on a Request, it would be simpler if we could just pass the desired method to Execute directly, i.e:
resp, err := resty.R().Execute(resty.POST, url)vs what I have to do right now:
type handler func(*resty.Request, string) (*resty.Response, error)
func get(r *resty.Request, url string) (*resty.Response, error) {
return r.Get(url)
}
func post(r *resty.Request, url string) (*resty.Response, error) {
return r.Post(url)
}
handlers := make(map[string]handler)
handlers[resty.GET] = get
handlers[resty.POST] = post
// etc
resp, err := handlers[resty.POST](resty.R(), url)