2.0.14 • Published 3 days ago

@devtea2027/omnis-possimus-minus-asperiores v2.0.14

Weekly downloads
-
License
MIT
Repository
github
Last release
3 days 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 @devtea2027/omnis-possimus-minus-asperiores --save

Usage

import { fetch } from "@devtea2027/omnis-possimus-minus-asperiores";

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 @devtea2027/omnis-possimus-minus-asperiores/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 "@devtea2027/omnis-possimus-minus-asperiores";

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

readablestreamObject.valuestestingautoprefixeriterate_.extendReactiveXcoregradients cssECMAScript 5valuesargumentsdeephelpersopenmomentsigtermless.jsopensstreamsES2021envpropertiesSymboldebuggerrdsterminalsortpropertyArrayBuffer.prototype.sliceoutputECMAScript 2015AsyncIteratorUnderscorerestfulio-tsglobalsfiltergetintrinsicfile systemreusefindLastIndexconnecthashlesscssconcatflatMapless cssfull-widtheslintpluginvariablesresteventslengthcommanderequalitysetPrototypeOfassertioncommand-lineArray.prototype.findLastIndexfind-uplinewrapfast-copyECMAScript 2018stylingargscjkReactiveExtensionshardlinksjavascriptsequenceerror-handlingformchecktypanionhookformwatcherbreakprefixlimitbrowsersigintargvObject.definePropertyimportexportgroupartvisualmetadatacollection.es6cssObject.getPrototypeOfsortedserializedefinees8identifierssetpreserve-symlinksfunctionInt32Arraystringifierless mixinslazyES7spinnersextensionES2017reduxUint32Arrayexpressamazonmodulecreatefsutilitylastgetdom-testing-librarysqslogchromiumCSSasciiuninstallFloat64ArrayincludesObject.entriescss-in-jsinputsidecolumnWebSocketscore-jssesdataViewprotobufworkspace:*assertcodesPushbluebirdtypeconsolestdlibresolvecompilerautoscalingstructuredClonepromisefullECMAScript 2020ArrayBuffer#sliceemojirm -frquoteeveryglobcharacterpluginstatelessjoistableflatfastES2023iteratorinterruptsdefinePropertyconsumeES6privateserializerflagexpressiondefaultinstalllimitedfastclonepropdependency managerirqparentshotimmutableinvarianteventDispatcherkeyswordbreakmacossuperstructstylesbeanstalkfindLastdeepcopyRegExp.prototype.flagsoffsetenvironmentsswfRxtermsettermergeRxJSawesomesaucecachetoolslockfileMicrosoftcorsnameswrapboundauthenticationnumberkoreangradients css3TypeBoxprocesswritablemimeworkflowdescriptorsafergbPromiseuuidcliwordwraprandomwafjsonhas-ownArray.prototype.containsclassnamegetPrototypeOftrimRightReflect.getPrototypeOfBigUint64ArrayJSON-SchemaairbnbtrimLefteslint-pluginsignalsargumentspinnernopematchesagentpyyamlECMAScript 7fast-clonenegative zeronpmforEachlinuxurlcircularES5handlerssomedependenciesparsingownregexformstypedArrayBufferentriesargparsecloudfrontlook-upes5streams2throttlefpsnamermxtermObject.assignemitcall-boundbuffercallwatchstyleURLstyled-componentslivefromuptrimStartpushbyteLengthpackagegetOwnPropertyDescriptorxdgvarses2016class-validatorquerystringestypedarraypackage.jsonexitcopychaiinstallerspecutilitiesESnextsignaltrimEndstaterateArray.prototype.flattensettingscoerciblehasmake dircolumnswaitformattingelmtoArray.envefficientpasswordbrowserslistfunctionalIteratoravaArray.prototype.findLastglaciersyntaxerrores6jestcloudwatchjwtmapspawnbindopeneri18ngenericses7deep-clonepostcssiamsyntaxec2mkdirsfluxwhichweakmapfixed-widthArray.prototype.flatMaptsenvironmentes2015loadbalancingeslintreact-hook-formfseventsapimime-dbmiddlewareloggerdeterministicdotenvjapaneseawaitponyfillutilaccessorasyncreplaycss lesstypeerrorkarmacolourmixinsdeepclonetc39figletviewArray.prototype.flatRegExp#flagsECMAScript 3setImmediateratelimitlistenerscss nestinges-abstractjsbootstrap lesstelephone
2.0.14

3 days ago

2.0.13

4 days ago

2.0.11

6 days ago

2.0.12

5 days ago

2.0.10

7 days ago

1.0.10

8 days ago

1.0.9

9 days ago

1.0.8

10 days ago

1.0.7

11 days ago

1.0.6

12 days ago

1.0.5

13 days ago

1.0.4

14 days ago