Git Product home page Git Product logo

fetch's Introduction

This repository is now archived. See this post for more details: #83

Fetch Monorepo

This fetch monorepo contains three packages:

  • @vercel/fetch
  • @vercel/fetch-retry
  • @vercel/fetch-cached-dns

These packages are designed for use with Node.js in order to bring the familiarity of the Fetch API to the backend. There are future plans to make this project interoperable between both browser and server environments.

Getting Started

@vercel/fetch bundles all packages inside this monorepo together into a super-powered fetch client. By default, this package will use its peer dependency node-fetch, but it also supports other fetch implementations.

// Basic Usage
import fetch from '@vercel/fetch';
// Bring your own fetch implementation
import createFetch from '@vercel/fetch';
import fetchImpl from 'some-fetch-implementation';
const fetch = createFetch(fetchImpl);

Contributing

Please see our CONTRIBUTING.md

Code of Conduct

Please see our CODE_OF_CONDUCT.md

fetch's People

Contributors

a-ursino avatar andybitz avatar arunoda avatar calebboyd avatar dependabot[bot] avatar ethan-arrowood avatar gaspar09 avatar github-actions[bot] avatar igorklopov avatar jamo avatar javivelasco avatar leo avatar lsb avatar lucleray avatar matheuss avatar msftenhanceprovenance avatar nkzawa avatar ofhouse avatar olliv avatar pranaygp avatar qix- avatar rauchg avatar runeh avatar rymndhng avatar styfle avatar timneutkens avatar tootallnate avatar zkochan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fetch's Issues

This doesn't have some deps.

See logs:

> now-rm@ start /usr/src/app
> micro -p 3000 .

micro: Error when importing /usr/src/app: Error: Cannot find module '@zeit/fetch-retry'
    at Function.Module._resolveFilename (module.js:527:15)
    at Function.Module._load (module.js:476:23)
    at Module.require (module.js:568:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/usr/src/app/node_modules/@zeit/fetch/index.js:1:87)
    at Module._compile (module.js:624:30)
    at Object.Module._extensions..js (module.js:635:10)
    at Module.load (module.js:545:32)
    at tryModuleLoad (module.js:508:12)
    at Function.Module._load (module.js:500:3)
micro: https://err.sh/micro/invalid-entry

This happens when I run this on k8s.

vercel/fetch returns 404 for calls that were returning 200 prior

Found this bug while working with transitive-bullshit/react-static-tweets#43 and posted a gnarly post-install work-around over there.

The issue happens when doing a GET call on some endpoints, mine specifically being https://syndication.twitter.com/tweets.json?ids=296658470705438720.

I've confirmed with local calls in a (very friendly) loop to https://syndication.twitter.com/tweets.json?ids=296658470705438720 that that endpoint isn't intermittently returning 404. Actually, on the application instance, once a single 404 is returned it continues to return 404s which might indicate a state-related issue within vercel/fetch.

This is the line that causes the issue 404 in the aforementioned repo:
https://github.com/transitive-bullshit/react-static-tweets/blob/4ff2e4e6eb138c3a98f364beb0117f0e2d5acc90/packages/static-tweets/src/twitter/api.ts#L16

I'll post more information / PR if I find anything helpful.

Action required: Greenkeeper could not be activated 🚨

🚨 You need to enable Continuous Integration on all branches of this repository. 🚨

To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because it uses your CI build statuses to figure out when to notify you about breaking changes.

Since we didn’t receive a CI status on the greenkeeper/initial branch, it’s possible that you don’t have CI set up yet. We recommend using Travis CI, but Greenkeeper will work with every other CI service as well.

If you have already set up a CI for this repository, you might need to check how it’s configured. Make sure it is set to run on all new branches. If you don’t want it to run on absolutely every branch, you can whitelist branches starting with greenkeeper/.

Once you have installed and configured CI on this repository correctly, you’ll need to re-trigger Greenkeeper’s initial pull request. To do this, please delete the greenkeeper/initial branch in this repository, and then remove and re-add this repository to the Greenkeeper App’s white list on Github. You'll find this list on your repo or organization’s settings page, under Installed GitHub Apps.

Should the types be moved to dev dependencies?

If the package is used in a javascript project, a warning is thrown:

warning " > @vercel/[email protected]" has unmet peer dependency "@types/node-fetch@2".

If this was moved to dev dependencies, it would stop that error from showing up I believe. Also, we could probably move @types/async-retry down to dev dependencies too while we're at it.

Would there be any problems I'm not foreseeing if I made this change?

retrying non-idempotent and non-safe requests is considered harmful

Hello,

thanks for providing this handy fetch replacement.

I wanted to provide feedback based on our usage of the lib. We were recently surprised to discover, that fetch-retry also retries non-idempotent and non-safe http requests (see the http spec section 9.2). This can lead to unintended effects on the target server.

I would suggest, that by default, fetch-retry should only retry idempotent or safe methods as defined by the spec, and optionally provide a setting, so that all methods are retried. In order to avoid a breaking change, it would also be viable to leave the default as is, and explain in the docs, how the spec compliant behaviour can be setup.

I would be open to contribute if we can agree on a solution.

debug package missing?

Error: Cannot find module 'debug'
    at Function.Module._resolveFilename (module.js:542:15)
    at Function.Module._load (module.js:472:25)
    at Module.require (module.js:585:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/home/hbp/repos/zeit/now-gc/node_modules/@zeit/fetch/index.js:5:15)
    at Module._compile (module.js:641:30)
    at Object.Module._extensions..js (module.js:652:10)
    at Module.load (module.js:560:32)
    at tryModuleLoad (module.js:503:12)
    at Function.Module._load (module.js:495:3)

Smaller pool by default

Right now it's 200, which is good for many use cases, but overkill for others. As an example, if you write a little utility that abstracts over fetch, and someone uses it as a module, they get a 200 socket pool by default.

A more reasonable default would be 50

BUG while pass FormData `body` it will always into

while we passed FormData in server side , it will run into these code,

opts.body = JSON.stringify(opts.body);
opts.headers.set('Content-Type', 'application/json');
opts.headers.set('Content-Length', Buffer.byteLength(opts.body));

But for form-data in server side, maybe sometimes we need to passfs.createReadStream as form-data

it should not set header 'Content-Type', 'application/json'

Documentation and types are incorrect / incomplete

I can't get this module to work, because

import fetch from '@vercel/fetch';

Is incorrect

{
  message: "fetch() argument isn't a function; did you forget to initialize your `@vercel/fetch` import?",
  code: -32603,
  data: {
    code: 'INTERNAL_SERVER_ERROR',
    httpStatus: 500,
    path: 'krakenRouter.sendError'
  }
}

There is no complete example here.

Cannot find requested import 'RequestInit'

I am using the https://nextjs.org/commerce and a line within that is attempting the following

import type { RequestInit } from '@vercel/fetch'
Which is not a named export from this library.

In my package.json it says I have version
"@vercel/fetch": "^6.1.0",
Which is the most recent one. Is this export still available in the latest version of the library?

Consider not mutating provided opts object

We are facing an issue when migrating from node-fetch to @zeit/fetch due to the fact that some of the properties in provided opts object are mutated before calling the decorated fetch function.

We are having issues mainly with headers, but I see the body is overwritten too.

Maybe it would be a good idea to copy provided opts and mutate the copy before passing to the wrapped fetch instead? It would remove these unexpected side effects.

I think I could try to provide the fix if you are ok with it.

Archiving `@vercel/fetch`

We will be archiving this repository in favor of fetch in Node.js. Existing versions will not be deprecated and can be continued to be used. This project has worked well, but with the latest options from Node.js, we believe it’s now sufficient to replace this library.

The native Fetch within Node.js (vendored from Undici) is more spec-compliant than the default node-fetch this library ships. Plus, it utilizes a keep-alive agent by default. Retry logic is coming soon and other libraries exist to fill this need if you are looking to implement it yourself (such as async-retry).

Thank you to all the community contributions!

`Host` header is not properly rewritten upon 3xx redirect

Ex:

const fetch = require('@zeit/fetch')(require('node-fetch'))
const url = 'https://github.com/paulkernfeld/node-headless/tarball/master'

async function main() {
  const res = await fetch(url, {
    headers: {
      'User-Agent': 'ace'
    }
  })
  console.log(res)
}

main().catch(err => {
  console.error(err);
  process.exit(1);
});

Can't resolve 'dns'

Hello,

I'm trying to use @vercel/fetch in nextjs on the serverside
Whatever I try I always have the same error:

./node_modules/@zeit/dns-cached-resolve/lib/dns-resolve.js:6:0
Module not found: Can't resolve 'dns'

Am I doing something wrong?

Thanks for your help.

Feature Request: Add support for passing Request object

Vanilla fetch supports passing a Request object as its first parameter. This works really great for flows that incrementally build out a Request object to then pass to fetch.

This API is also supported in node-fetch, which exports a Request implementation in its package. But when wrapping node-fetch with @vercel/fetch, and passing a Request object, an error is thrown: The "url" argument must be of type string. Received an instance of Request. This means none of our flows that worked with node-fetch and vanilla fetch will work with @vercel/fetch.

Is there any intention on supporting passing a Request object, as is described in the fetch spec?

Domains defined in the /etc/hosts file do not resolve

I am using Craft Nitro (https://getnitro.sh/) for local CMS development and connecting to the api using @vercel/fetch. Nitro provides URL's that look like https://testcms.nitro and updates the /ect/hosts file with that domain. However these domains do not resolve using @vercel/vetch

It looks like this is happening because https://github.com/vercel/dns-cached-resolve is using dns.resolve4/dns.resolve6 both of which ignore the hosts file. Looking into the node DNS documentation it looks like dns.lookup uses the system DNS lookup which does look at /etc/hosts however there are performance implications when using it (https://nodejs.org/api/dns.html#implementation-considerations)

https://github.com/vercel/dns-cached-resolve special cases localhost, but It might be a good idea to allow a fallback to dns.lookup when dns.resolve fails to allow other domains defined in /etc/hosts to work. This could be an option set when setting up @vercel/fetch and it would allow enabling / disabling this behaviour depending on environment.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.