Coder Social home page Coder Social logo

node-superfetch's Introduction

node-superfetch

Downloads Version

node-superfetch is a tiny little wrapper for Node.js' fetch API that makes it look like you are using superagent.

Basic Usage

const request = require('node-superfetch');

try {
	const { body } = await request.get('https://registry.npmjs.com/node-superfetch');
	console.log(body);
} catch (err) {
	console.error(err);
}

Usage is basically that of superagent or snekfetch, and implements the same HTTP methods, as well as functions like query (sets query parameters), set (sets headers), send (for adding POST data and such), attach (for sending FormData), redirects (for setting the allowed number of redirects), and agent (for setting the HTTP agent). end is also supported for callbacks.

Additionally, you can also use the noResultData option to get everything except the actual result data of the request. This is essentially doing the request without calling any methods to parse the result data.

const { headers, url } = await request.get('https://registry.npmjs.com/node-superfetch', { noResultData: true });
console.log(url); // should log https://registry.npmjs.com/node-superfetch

node-superfetch's People

Contributors

appellation avatar dependabot-preview[bot] avatar dependabot[bot] avatar dragonfire535 avatar papaia avatar

Stargazers

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

Watchers

 avatar  avatar  avatar

node-superfetch's Issues

[typings] Cannot find name Blob

When compiling with gulp, the error below is thrown.

[13:16:10] Using gulpfile ~\Documents\Development\Cooking\cooking-tools\gulpfile.js
[13:16:10] Starting 'default'...
[13:16:10] Finished 'default' after 52 ms 
path-to-/node_modules/node-superfetch/typings/index.d.ts(5,45): error TS2304: Cannot find name 'Blob'.

That refers to this line:

type RequestBody = null | string | Buffer | Blob | NodeJS.ReadableStream;

headers

Please describe the problem you are having in as much detail as possible:
How do I use headers with this (an example would be nice)

Further details:

  • node-superfetch version:
  • Node.js version:
  • Operating system:
  • Priority this issue should have – please be realistic and elaborate if possible:

error

Please describe the problem you are having in as much detail as possible:
some unknown error occurs when I'm trying to run my project

/home/root/lfheroes-bot/node_modules/node-superfetch/index.js:136
        Request[method.toLowerCase()] = (url, options) => new Request({ url, method, ...options });
                                                                                     ^^^

SyntaxError: Unexpected token ...
    at createScript (vm.js:74:10)
    at Object.runInThisContext (vm.js:116:10)
    at Module._compile (module.js:533:28)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)
    at Module.require (module.js:513:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/home/root/lfheroes-bot/node_modules/hastebgen-js/index.js:1:79)

Further details:

  • node-superfetch version: 0.19
  • Node.js version: 6.9.0
  • Operating system: ubuntu 18.04.2
  • Priority this issue should have – please be realistic and elaborate if possible: HIGH

TypeError: response.buffer is not a function

Please describe the problem you are having in as much detail as possible:
TypeError: response.buffer is not a function. This is likely a node-related issue. Please add support.

The alternative to .buffer() is now .arrayBuffer()

Further details:

  • node-superfetch version: 3.0.0
  • Node.js version: v18.10.0
  • Operating system: Arch Linux

node-fetch ESM support

Please describe the problem you are having in as much detail as possible:
Some months ago node-fetch dropped support for CJS, and they have totally moved to ESM. I'd like to know if you convert n-superfetch for ESM support, since node-fetch v2 is no longer have active development, and prefer to move to v3

  • node-superfetch version: 0.2.3
  • Node.js version: 16.13.2
  • Operating system: Ubuntu
  • Priority this issue should have – please be realistic and elaborate if possible: Medium since some pepes still want to stick with CJS and it might be a bit difficult for newbies to adopt ESM.

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.