RafaelYon / requestfy

A library to facilitate creation of HTTP requests in GO
MIT License
4 stars 3 forks source link

Allow specifying body for all requests #28

Open RafaelYon opened 2 years ago

RafaelYon commented 2 years ago

We should be able to specify a body for all types of requests in a standardized way and also provide some methods to facilitate the encode for popular formats such as JSON

_Originally posted by @RafaelYon in https://github.com/RafaelYon/requestfy/pull/27#discussion_r987432318_

RafaelYon commented 2 years ago

With the changes made in the test package to try to make the APIs compatible due to the addition of a second parameter in some requests made in PR #26 and #25

I believe we should move the request body specification to a second helper method, something like:

func (r *Request) Body(body io.Reader) {
    ...
}

This way we keep the API compatibility of the HTTP methods and we can even create other helper methods to facilitate encoding popular formats like JSON:

func (r *Request) JsonBody(v interface{}) error {
    ...
}