Replacement for http package using fetch

As you might have realized, the http package will soon be deprecated, since it uses the deprecated request on the server.

However this would break a lot in our code, since it is a great isomorphic abstraction to HTTP calls and I managed to replace request with node-fetch on the server and kept the client code as it is.

You can check out the package on atmosphere and on GitHub.

Install via meteor remove http && meteor add jkuester:http

The API is 95% the same, expect for npmRequestOptions that were removed due to request being removed.

Any feedback is very welcomed!

8 Likes

There is the fetch package which is suppose to replace the http package, but it is not documented in the docs.
This is a good transition though!

nice work! since Meteor offers isomorphic fetch couldn’t you use the same code that you have for the server in your package more or less and use Meteor’s fetch to provide an http package compat. layer?

This could be a good direction. I simply didn’t touch the client code, since tests passed and I am currently a bit under pressure to deliver at work :sweat_smile:

4 Likes

@jkuester thanks so much for doing this. I spent about 4 hours yesterday trying to convert some of my REST calls to use fetch, and I was completely buried in all of the encoding issues, and trying to get the URL parameters and body in shape. In particular, Twilio was driving me crazy.

I just replaced all of that with your HTTP and it is working perfectly. Thanks again :unicorn:

3 Likes

Just updated to 2.0. Got the deprecation warning in my logs. From my packages, the following are dependent on HTTP:

  • facebook-oauth
  • mdg:meteor-apm-agent
  • mizzao:timesync

@jkuester am I right in thinking that under normal circumstances, if I use your HTTP package those aforementioned packages automatically default to it?

am I right in thinking that under normal circumstances, if I use your HTTP package those aforementioned packages automatically default to it?

Unfortunately not, because HTTP is not a global export and thus the accounts- packages will use the deprecated version (using request). This is why I’d like to discuss this topic. We have several options:

  • update accounts (and other core packages) to use fetch
  • update http to use the fetch (via merging jkuester:http into http)
  • keep accounts packages use the (updated/merged) http until they have been migrated
  • other options?
1 Like

On a project level, what we did as a transition is to copy jkuester:http to /packages/http folder and rename the package as http

1 Like

I think we should do a major version upgrade to http where we merge your package in. In the meantime upgrading as much as possible in Meteor core to fetch would be great.

OK I will open a PR tonight

1 Like

Did the initial replacement in the usage (just the code, so far no testing, so there are probably mistakes):