Installations
npm install popsicle
Releases
Fix missing dependency
Published on 21 Nov 2023
Update `popsicle-transport-http` and `popsicle-cookie-jar` min versions
Published on 21 Nov 2023
XHR ArrayBuffer
Published on 07 Oct 2020
Update Servie and HTTP transport
Published on 11 Sept 2020
Updated Dependencies
Published on 03 Nov 2019
Export `toFetch`
Published on 05 Jul 2019
Developer
serviejs
Developer Guide
Module System
CommonJS, UMD
Min. Node Version
>=8
Typescript Support
Yes
Node Version
21.0.0
NPM Version
10.2.0
Statistics
246 Stars
369 Commits
19 Forks
8 Watching
33 Branches
10 Contributors
Updated on 30 May 2024
Languages
TypeScript (100%)
Total Downloads
Cumulative downloads
Total Downloads
77,048,166
Last day
-7.2%
38,003
Compared to previous day
Last week
3.7%
219,100
Compared to previous week
Last month
13.1%
880,259
Compared to previous month
Last year
-6.1%
10,595,626
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Advanced HTTP requests in node.js and browsers, using Servie.
Installation
npm install popsicle --save
Usage
1import { fetch } from "popsicle"; 2 3const res = await fetch("http://example.com"); 4const 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 importingpopsicle/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:
- Default
User-Agent
(Learn more) - Decodes
gzip
,deflate
andbrotli
(Learn more) - Follows HTTP redirects (Learn more)
- In-memory cookie cache (Learn more)
- Automatic HTTP2 and HTTP1 support and DNS caching (Learn more)
Important: If you are doing anything non-trivial with Popsicle, please override the
User-Agent
and respectrobots.txt
.
Recipes
Aborting a Request
1import { fetch, AbortController } from "popsicle"; 2 3const controller = new AbortController(); 4 5setTimeout(() => controller.abort(), 500); 6 7const res = fetch("http://example.com", { 8 signal: controller.signal, 9});
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
- Popsicle Status - Reject on invalid HTTP status codes
- Popsicle Retry - Retry HTTP requests on bad server responses
Creating Plugins
See Throwback for more information:
1type Plugin = ( 2 req: Request, 3 next: () => Promise<Response>, 4) => 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
No vulnerabilities found.
Reason
security policy file detected
Details
- Info: security policy file detected: SECURITY.md:1
- Info: Found linked content: SECURITY.md:1
- Info: Found disclosure, vulnerability, and/or timelines in security policy: SECURITY.md:1
- Info: Found text in security policy: SECURITY.md:1
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
9 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-gcx4-mw62-g8wm
- Warn: Project is vulnerable to: GHSA-92r3-m2mg-pj97
- Warn: Project is vulnerable to: GHSA-c24v-8rfc-w8vw
- Warn: Project is vulnerable to: GHSA-8jhw-289h-jh2g
- Warn: Project is vulnerable to: GHSA-64vr-g452-qvp3
- Warn: Project is vulnerable to: GHSA-9cwx-2883-4wfx
Reason
Found 0/16 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 14 are checked with a SAST tool
Score
2.7
/10
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More