Skip to content

Tiny optimized `fetch()`-like node.js and browser method with binary/JSON, CORS, redirects & SSL pinning

License

Notifications You must be signed in to change notification settings

paulmillr/micro-ftch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

micro-ftch

Tiny optimized fetch()-like node.js and browser method with binary/JSON, CORS, redirects & SSL pinning.

Also, take a look at fetch-streaming.

Usage

Can be used in browser and in node.js.

npm install micro-ftch

const fetch = require('micro-ftch');
fetch('https://google.com').then(...)

Options

The list of options that can be supplied as second argument to fetch(url, opts):

export type FETCH_OPT = {
  method?: string;
  type?: 'text' | 'json' | 'bytes'; // Response encoding (auto-detect if empty)
  redirect: boolean; // Follow redirects
  expectStatusCode?: number | false; // Expect this status code
  headers: Record<string, string>;
  data?: object; // POST/PUT/DELETE request data
  full: boolean; // Return full request {headers, status, body}
  keepAlive: boolean; // Enable keep-alive (node only)
  cors: boolean; // Allow CORS safe-listed headers (browser-only)
  referrer: boolean; // Send referrer (browser-only)
  sslAllowSelfSigned: boolean; // Allow self-signed ssl certs (node only)
  sslPinnedCertificates?: string[]; // Verify fingerprint of certificate (node only)
  _redirectCount: number;
};

License

MIT License (c) 2020, Paul Miller (https://paulmillr.com)