go-resty / resty

Simple HTTP and REST client library for Go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Feature request: the ability to indicate content-type when the server does not provide it

ccp-ccollins opened this issue · comments

Sometimes I am forced to get data from a server that has a consistent API (for example, it always returns JSON) but does not set the Content-Type header. In these cases, it appears that resty does not automatically parse the response automatically with SetResponse().

In cases where I know for sure what data should be expected, I'd like to be able to indicate that, rather than reading the body and parsing manually. For example, it could be something like this:

resty.R().
    SetResult(&output).
    ExpectContent("application/json").
    Get(url)

It seems nice addition to resty. Thank you, let me think of Content-Type fallback option for response and get back to you.

@ccp-ccollins I have added this feature. Available on branch expect-content-type f6639301f648551def9461e791a8b789e60fb9ee

Please give it try and share your feedback, then I will merge it to master. You can expect this feature in v1.0 release.

@ccp-ccollins whenever you get a chance, try and share your feedback. Thanks.

@ccp-ccollins Did you get a chance try it out?