Advanced HTTP requests in node.js and browsers, using Servie.
npm install popsicle --save
;const res = await ;const data = await restext;
Popsicle is a universal package, meaning node.js and browsers are supported without any configuration. This means the primary endpoint requires some
domtypes in TypeScript. When in a node.js or browser only environments prefer importing
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.
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.
The middleware stack for node.js includes normalization to act similar to browsers:
- Support for decoding compressed payloads
- Follows HTTP redirects
- Caches cookies in-memory
Important: If you are doing anything non-trivial with Popsicle, please override the
Aborting a Request
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)
Build the functionality you require by composing middleware functions and using
src/node.ts for an example.
- Popsicle Status - Reject on invalid HTTP status codes
- Popsicle Retry - Retry HTTP requests on bad server responses
See Throwback for more information:
This project is written using TypeScript and publishes the types to NPM alongside the package.
- Superagent - HTTP requests for node and browsers
- Fetch - Browser polyfill for promise-based HTTP requests
- Axios - HTTP request API based on Angular's