Skip to content

Make Request.execute public #12

@bmurphy1976

Description

@bmurphy1976

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)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions