popsicle
Simple HTTP requests for node and the browser
Last updated 8 years ago by blakeembrey .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install popsicle 
SYNC missed versions from official npm registry.

Popsicle

NPM version NPM downloads Build status Test coverage Bundle size

Advanced HTTP requests in node.js and browsers, using Servie.

Installation

npm install popsicle --save

Usage

import { fetch } from "popsicle";

const res = await fetch("http://example.com");
const data = await res.text();

Popsicle is a universal package, meaning node.js and browsers are supported without any configuration. This means the primary endpoint requires some dom types in TypeScript. When in a node.js or browser only environments prefer importing popsicle/dist/{node,browser} instead.

Popsicle re-exports Request, Response, Headers and AbortController from servie. The fetch function accepts the same arguments as Request and returns a promise that resolves to Response. You can use the Signal event emitter (from AbortController#signal) to listen to request life cycle events.

Browser

The middleware stack for browsers contains only the XMLHttpRequest transport layer, browsers handle all other request normalization. This means a smaller and faster package for browsers.

Node.js

The middleware stack for node.js includes normalization to act similar to browsers:

Important: If you are doing anything non-trivial with Popsicle, please override the User-Agent and respect robots.txt.

Recipes

Aborting a Request

import { fetch, AbortController } from "popsicle";

const controller = new AbortController();

setTimeout(() => controller.abort(), 500);

const res = fetch("http://example.com", {
  signal: controller.signal,
});

Errors

Transports can return an error. The built-in codes are documented below:

  • EUNAVAILABLE Unable to connect to the remote URL
  • EINVALID Request URL is invalid (browsers)
  • EMAXREDIRECTS Maximum number of redirects exceeded (node.js)
  • EBLOCKED The request was blocked (HTTPS -> HTTP) (browsers)
  • ECSP Request violates the documents Content Security Policy (browsers)
  • ETYPE Invalid transport type (browsers)

Customization

Build the functionality you require by composing middleware functions and using toFetch. See src/node.ts for an example.

Plugins

Creating Plugins

See Throwback for more information:

type Plugin = (
  req: Request,
  next: () => Promise<Response>,
) => Promise<Response>;

TypeScript

This project is written using TypeScript and publishes the types to NPM alongside the package.

Related Projects

  • Superagent - HTTP requests for node and browsers
  • Fetch - Browser polyfill for promise-based HTTP requests
  • Axios - HTTP request API based on Angular's $http service

License

MIT

Current Tags

  • 12.1.2                                ...           latest (a year ago)
  • 10.0.1                                ...           legacy (6 years ago)
  • 11.0.0-3                                ...           next (6 years ago)

99 Versions

  • 12.1.2                                ...           a year ago
  • 12.1.1                                ...           a year ago
  • 12.1.0                                ...           4 years ago
  • 12.0.6                                ...           4 years ago
  • 12.0.5                                ...           5 years ago
  • 12.0.4                                ...           5 years ago
  • 12.0.3                                ...           5 years ago
  • 12.0.2                                ...           5 years ago
  • 12.0.1                                ...           5 years ago
  • 12.0.0                                ...           5 years ago
  • 11.0.5                                ...           5 years ago
  • 11.0.4                                ...           6 years ago
  • 11.0.3                                ...           6 years ago
  • 11.0.2                                ...           6 years ago
  • 11.0.1                                ...           6 years ago
  • 11.0.0                                ...           6 years ago
  • 11.0.0-3                                ...           6 years ago
  • 11.0.0-2                                ...           6 years ago
  • 11.0.0-1                                ...           6 years ago
  • 10.0.1                                ...           6 years ago
  • 11.0.0-0                                ...           6 years ago
  • 10.0.0                                ...           6 years ago
  • 9.2.0                                ...           7 years ago
  • 9.1.0                                ...           8 years ago
  • 9.0.0                                ...           8 years ago
  • 8.2.0                                ...           8 years ago
  • 8.1.1                                ...           8 years ago
  • 8.1.0                                ...           8 years ago
  • 8.0.4                                ...           8 years ago
  • 8.0.3                                ...           8 years ago
  • 8.0.2                                ...           8 years ago
  • 8.0.1                                ...           8 years ago
  • 8.0.0                                ...           8 years ago
  • 7.0.1                                ...           8 years ago
  • 7.0.0                                ...           8 years ago
  • 6.2.2                                ...           8 years ago
  • 6.2.1                                ...           8 years ago
  • 6.2.0                                ...           9 years ago
  • 6.1.0                                ...           9 years ago
  • 6.0.0                                ...           9 years ago
  • 5.0.1                                ...           9 years ago
  • 5.0.0                                ...           9 years ago
  • 4.0.0                                ...           9 years ago
  • 3.2.2                                ...           9 years ago
  • 3.2.1                                ...           9 years ago
  • 3.2.0                                ...           9 years ago
  • 3.1.1                                ...           9 years ago
  • 3.0.3                                ...           9 years ago
  • 3.0.2                                ...           9 years ago
  • 3.0.1                                ...           9 years ago
  • 3.0.0                                ...           9 years ago
  • 2.0.2                                ...           9 years ago
  • 2.0.1                                ...           9 years ago
  • 2.0.0                                ...           9 years ago
  • 1.4.0                                ...           9 years ago
  • 1.3.2                                ...           9 years ago
  • 1.3.1                                ...           9 years ago
  • 1.3.0                                ...           9 years ago
  • 1.2.2                                ...           9 years ago
  • 1.2.1                                ...           9 years ago
  • 1.2.0                                ...           9 years ago
  • 1.1.1                                ...           9 years ago
  • 1.1.0                                ...           9 years ago
  • 1.0.0                                ...           9 years ago
  • 0.5.13                                ...           9 years ago
  • 0.5.12                                ...           10 years ago
  • 0.5.11                                ...           10 years ago
  • 0.5.10                                ...           10 years ago
  • 0.5.9                                ...           10 years ago
  • 0.5.8                                ...           10 years ago
  • 0.5.7                                ...           10 years ago
  • 0.5.6                                ...           10 years ago
  • 0.5.5                                ...           10 years ago
  • 0.5.4                                ...           10 years ago
  • 0.5.3                                ...           10 years ago
  • 0.5.2                                ...           10 years ago
  • 0.5.1                                ...           10 years ago
  • 0.5.0                                ...           10 years ago
  • 0.4.0                                ...           10 years ago
  • 0.3.11                                ...           10 years ago
  • 0.3.10                                ...           10 years ago
  • 0.3.9                                ...           10 years ago
  • 0.3.8                                ...           10 years ago
  • 0.3.7                                ...           10 years ago
  • 0.3.6                                ...           10 years ago
  • 0.3.5                                ...           10 years ago
  • 0.3.4                                ...           10 years ago
  • 0.3.3                                ...           10 years ago
  • 0.3.2                                ...           10 years ago
  • 0.3.1                                ...           10 years ago
  • 0.3.0                                ...           10 years ago
  • 0.2.2                                ...           10 years ago
  • 0.2.1                                ...           10 years ago
  • 0.2.0                                ...           10 years ago
  • 0.1.1                                ...           10 years ago
  • 0.1.0                                ...           10 years ago
  • 0.0.3                                ...           10 years ago
  • 0.0.2                                ...           10 years ago
  • 0.0.1                                ...           10 years ago
Maintainers (1)
Downloads
Total 0
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (8)
Dev Dependencies (12)

© 2010 - cnpmjs.org x YWFE | Home | YWFE