Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to handle empty HTTP Response #12

Closed
glossd opened this issue Nov 10, 2024 · 1 comment · Fixed by #16
Closed

How to handle empty HTTP Response #12

glossd opened this issue Nov 10, 2024 · 1 comment · Fixed by #16

Comments

@glossd
Copy link
Owner

glossd commented Nov 10, 2024

Right now I have to specify the type in HTTP methods. E.g. Delete method usually returns no content.
I do have fetch.GetJ shortcut for fetch.Get[fetch.J], I could add fetch.DeleteNoContent or something, but I don't really like it.
However, I need to check the status of the HTTP response so I would use it like this

var url = ...
res, err := fetch.Delete[fetch.Response[string]](url)
if err != nil {
    panic(err)
}
if res.Status == 200 {
     // delete success
}

I don't need to specify the string. The problem is that the generic interface is not inferred
I could add fetch.NoContent for which you don't need to specify a type parameter but it would have all of the http data from fetch.Response

@glossd
Copy link
Owner Author

glossd commented Nov 11, 2024

NoContent is an HTTP status 204, could be confusing. Empty from grpc sounds better, but still not good enough. fetch.EmptyResponse is a bit long.
And I can see another use-case, what if I don't care about the body, well you can use HEAD method if the server supports it, or I could use fetch.EmptyResponse which will skip reading the body.
The name isn't clear yet, it should represent fetch.Response which does not read/marshal the body.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant