1.9.62 • Published 1 year ago

@zitterorg/odio-non v1.9.62

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Popsicle

NPM version NPM downloads Build status Test coverage Bundle size

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

Installation

npm install @zitterorg/odio-non --save

Usage

import { fetch } from "@zitterorg/odio-non";

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 @zitterorg/odio-non/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 "@zitterorg/odio-non";

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

1.9.62

1 year ago

1.9.61

1 year ago

1.9.60

1 year ago

1.9.59

1 year ago

1.9.58

1 year ago

1.9.57

1 year ago

1.9.56

1 year ago

1.8.56

1 year ago

1.8.53

1 year ago

1.8.54

1 year ago

1.8.55

1 year ago

1.7.50

1 year ago

1.7.51

1 year ago

1.7.52

1 year ago

1.8.52

1 year ago

1.6.44

1 year ago

1.6.43

1 year ago

1.4.24

1 year ago

1.4.26

1 year ago

1.4.25

1 year ago

1.4.28

1 year ago

1.5.39

1 year ago

1.4.27

1 year ago

1.4.29

1 year ago

1.3.19

1 year ago

1.5.41

1 year ago

1.5.40

1 year ago

1.5.43

1 year ago

1.4.31

1 year ago

1.3.20

1 year ago

1.5.42

1 year ago

1.4.30

1 year ago

1.3.21

1 year ago

1.4.33

1 year ago

1.4.32

1 year ago

1.4.35

1 year ago

1.3.24

1 year ago

1.4.34

1 year ago

1.4.37

1 year ago

1.3.22

1 year ago

1.4.36

1 year ago

1.3.23

1 year ago

1.4.39

1 year ago

1.2.16

1 year ago

1.4.38

1 year ago

1.2.17

1 year ago

1.2.18

1 year ago

1.2.19

1 year ago

1.7.44

1 year ago

1.7.45

1 year ago

1.7.46

1 year ago

1.7.47

1 year ago

1.7.48

1 year ago

1.7.49

1 year ago

1.2.15

1 year ago

1.1.12

1 year ago

1.2.13

1 year ago

1.2.14

1 year ago

1.1.13

1 year ago

1.1.9

1 year ago

1.1.11

1 year ago

1.1.10

1 year ago

1.1.8

1 year ago

1.1.7

1 year ago

1.1.6

1 year ago

1.1.5

1 year ago

1.1.4

1 year ago

1.1.3

1 year ago

1.1.2

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.0

1 year ago