-
-
Notifications
You must be signed in to change notification settings - Fork 341
Add HTTP support via Do, Get, Post #139
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
Conversation
Co-authored-by: Christoph Petrausch <263448+hikhvar@users.noreply.github.com> Co-authored-by: James Mills <prologic@shortcircuit.net.au> Co-authored-by: Carl Johnson <me@carlmjohnson.net>
@hikhvar @carlmjohnson @M3talM0nk3y @lalloni maybe you'd be interested in trying out this branch, as you've all had valuable input into the design. Does the Do/Get/Post API support the kind of programs you want to write involving HTTP requests? Can you find any bugs or unexpected behaviour? And is there anything missing which you need for real-world use cases? |
@bitfield Looks like it is taking shape. Have you thought about how to allow the user to configure underlying http client as well as provide custom headers for things like auth (basic and bearer, for example)? In the case of a POST/PUT/PATCH, is the idea to allow the body be provided from the standard input and/or a file? |
Thanks @M3talM0nk3y! If you need to customise the request in some way (for example headers), use Yes, |
One good question raised by @thiagonache is "what if you want the status code?" Right now, any non-2xx response sets an error and makes the pipe a no-op. But there are non-2xx status codes that aren't errors; for example, 304 Not Modified. What should we do in that case? |
Go automatically follows redirects. You only get a 304 if you set an ETAG/If-Not-Modifier header, in which case, you probably don't need the body anyway. So, it's probably mostly okay except if you want to log an error. Can the body be sent to stderr if it's a non-2XX response? |
@bitfield and I agreed that in most cases it's not a problem. I think the idea here is to check if someone has any valid case where a non-2XX response would be useful |
I would vote to leave it. If somebody really needs that special behavior, they could either implement an own Source returning a new pipe, or implementing a proper Filter. In other libraries I would make an own package for the detailed and customisable implementation of the source/filters. But as far as I understood this is against the philosophies of this library. |
This is a nice idea for the general problem of "if there's any error, the program just prints nothing". Maybe |
What about an script.Get(URL).Exit() and they might produce:
with
|
No description provided.