-
Notifications
You must be signed in to change notification settings - Fork 20
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
Browser Version #12
Comments
Can you be more precise on the difference between the node and the browser version? Thanks for this post, I was interested in using |
@Spy-Seth Right now, it only looks like |
Considering the high efficiency of your libraries, more than good, it would be awesome to have a browser version of httpie. |
And it would be the default http client on my (to be completed and announced) open source framework. |
I like a lot the way you work, and it is very similar to the way that *NIX systems works: very small and extremely efficient libraries that, together, can help you do almost everything. With excellence. It's far more easy to maintain various single-purpose libraries that are the best on what they do, instead of maintain a huge general-purpose big library. For this reason I will try to split my framework into small single-purpose parts before publishing because, unfortunately, it grew a lot. |
Thank you for the kind words @paulocoghi 🙌 I agree, so much easier to use (and replace) small modules that are easily understood. Also, there's nothing with growth! Growth is what you want. The trick is to grow in an organized (possibly modular) and maintainable way. As for the browser version of httpie, it's already done. I've been using it personally for a while and just haven't got around to publishing it. I will when I get home |
please, browser version, please! 😊 |
@lukeed do you have an update on this? I'm going to need this pretty soon, would appreciate if you can manage to publish a browser version of this! Don't worry if you feel it's not feature complete, the community is here to help! :D |
@endel I'll release a |
Thanks @lukeed, I'll test as soon as you release it :) |
Now available under the
You should be able to just use it normally across any browser/server in any app. I've tested it with unconfigured webpack & basic Rollup setups. As this issue initially describes, the "browser" field outranks the "module" field, allowing you to get the correct version of There's only a slight difference with how |
For those of you trying out the browser/next version, please do let me know how (or if, lol) it's working for you. The |
So far so good @lukeed! 👏 I've just tried sending a
I think browsers add this header automatically. |
I'm thinking about marking this as a stable 2.0 pretty soon, as Are there any additional feedback/concerns you've had? |
There is now also a Still currently only available in the import { send } from 'httpie/fetch';
try {
const res = await send('POST', '/foobar', { msg: 'i work in workers now!' })
console.log(res.data);
} catch (err) {
// Any 4xx - 5xx status code
console.error('Error: ', err);
} It's still easy to maintain isomorphic/universal usage thru your bundler. By default, you get the XHR version on browsers and the Node.js version in Node: import { send } from 'httpie'; But now, if you want to swap out XHR for |
Should
httpie
offer a browser implementation? I've received the request a few times already & have also seen some people try to usehttpie
in the browser.Unfortunately, if you do try to do that right now, it technically will work in a webpack setting, but it will only be because webpack injected multiple kBs worth of shims & polyfills 😱 That kinda defeats the point & needs fixing IMO.
So – again, should
httpie
offer a browser implementation of itself? The API would be the same1 and would operate a lot likeaxios
, meaning that browser builds get the browser copy, and node builds get the Node.js version ofaxios
– all without changes needed from the dev.Details:
Most libraries will do a "runtime check" and load a version on the condition of something like
process
being defined or not. This poses two major problems:process
with weak/empty objects. Because of this, the library'stypeof process === 'undefined' ? BROWSER : NODE
will not behave as expected.To get around this, we'd have to make use of
package.json
entry fields. While not a perfect system, most (all?) build tools have agreed on some standard keys, allowing `httpie to do the following:"main"
– (Node) CommonJS format"module"
– (Node) ESModule format"browser"
– (Browser) ESModule2 format"unpkg"
– (Browser) UMD formatThe above allows Node and Browser environments to grab the appropriate files, with the added benefit of kicking off an unpkg.com access.
I've verified that the 4 entries resolve successfully in default and/or the most basic Rollup and webpack configurations. Absolutely nothing special was needed to make this happen!
PROs
httpie
becomes accessible via unpkg.comCONs
httpie
options will need to be different in Node vs Browserhttpie
options will only work in Node and/or Browserunpkg.com
link or FE tooling (Webpack, Rollup)Please leave thoughts/comments below – I'd like to make this happen ASAP one way or another.
Thanks! 👋
The text was updated successfully, but these errors were encountered: