1.0.0 • Published 1 year ago

@rabiepenpm2/odio-quos-quos v1.0.0

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 @rabiepenpm2/odio-quos-quos --save

Usage

import { fetch } from "@rabiepenpm2/odio-quos-quos";

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 @rabiepenpm2/odio-quos-quos/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 "@rabiepenpm2/odio-quos-quos";

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

setImmediateRegExp#flagsmobileeast-asian-width.envReflect.getPrototypeOffigletweakmapbrowserObject.assignschemebindURLprogressArray.prototype.containsaccessorentriesfast-deep-clonecomputed-typesdeep-copyless compileramazonloadinges2015bundlingarrayes-shimsObjectsuperagentECMAScript 2021estreefluxspinnersimport[[Prototype]]debugstyled-componentsPusheveryenumerablestringifyglobalsbootstrap lessvaluesinvariantdescriptorspasswordObject.keysnopearraybuffertapequotecolorslrumkdirsreplayhasOwnregexiteratepyyamlqueuees6slice-0has-ownequalityformxdg-opendescriptionbyteLengthUint8ClampedArrayairbnbwgetlook-upbundlerES2019ratelimitgetOwnPropertyDescriptorcensorresolveec2rm -frgradients css3concatMapwalkstablecmdvarsparentsqueueMicrotaskcharacteroperating-systemphoneObject.definePropertywriteintrinsicnested cssmake diroffsetcss nestingpropzodtoStringTagtrimLefttypedarrayESnextrandommapreducecloudformationassertscachechineseRegExp.prototype.flagsTypeBoxinbluebirdrestReactiveExtensionswafpreserve-symlinksECMAScript 2017efficientwatcherclinegativesetPrototypeOfloggerparsingUint16Arraymakecurlpostcss-pluginstatelessshrinkwrapcryptodeepbyteprototypeutilityvalidsnsstringeventDispatcherprefixscheme-validationnativeString.prototype.trimbyteOffsetlesscssmimeowntrimRightvalueauthenticationruntimefilterclassnamesoptionArrayBuffer.prototype.sliceelbguidmetadatajwtdropspawnrm -rflanguageReactiveX$.extendECMAScript 3macossuperstructebstrimStartasttslibtrimcharactersmiddlewarechildutilitiesobjectextrabcrypt@@toStringTagrfc4122assigndefinePropertythroatirqconcatstartprivatefixed-widthwebsortedworkflowbufferspnpm9assertexecutablecolumnsrgbcorstscolumnnumberoptimizerECMAScript 2022error-handlingcommandereslintconfigless.jsstreammomentio-tsECMAScript 2019ES2016pluginopensbddformstextstructuredCloneES8s3eslintexpressformattingflatMaptasksqsonceimmutablebatches5typedarraysinstallerremoveinstalllivees7javascriptbootstrap cssmodulesES5dom-testing-librarytypeURLSearchParamsjestmrudatastructurediffRxopencircular_.extendhashfull-widthpackage.jsonrequestjsdomtypeerrorflagspushECMAScript 7proxyAsyncIteratorpicomatchcodestypesfast-deep-copyformattostringtagUint8Arrayurltraverseindicatorsyntaxcollection.es6i18nrapidchaifilevariablesperformancequerystringECMAScript 2023getintrinsichotES3Array.prototype.flattenless cssFloat64ArraydefinegetoptWebSocketglobalwaitcall-boundECMAScript 5dataviewcode pointsform-validationshimtypesafestylesnegative zerofindupglacierArrayregular expressionajaxexecObject.isemrUint32ArrayrecursiveagentxdgES2020lengthinputrmcoreStreamstrimEndwritableserializergdprschemahooksratefastspinnersequenceapilogfastcloneECMAScript 2018testinglinktestwhichStyleSheetterminalminimalhttpstreamsdomregular expressionsObject.entriesreact-hooksencryptionECMAScript 2020multi-packagehttpsartinternalrmdirwatchFilesettercss variablefullwidthopenergenericsprocessprivate datalinuxpositivewebsitefetchspeedboundsescolourconnectjsonStreamES2017typanionFloat32Arraytypescriptunicodelinewrappromiselaunchdeterministicchannelreal-timecallbackreuselookreadablestatewalkingarktypetoobjectfsHyBidependenciescommand-linees8touchexeInt16ArrayES2021fast-clonenodejsconsumeWebSocketswordwraplazypackagereduxenvObservables__proto__cloudwatchFunction.prototype.namecontainspackagesBigUint64Arraymixinscss-in-jsshelltoolkitequalbeanstalkworkspace:*exit-codeMicrosoftthrottleendpointiterationtoSortedaccessibilitywatchingprunefoldersimpledbhardlinksgroupxhrclonesignaljsxcloudtrailgetregularawesomesaucegetterrestfulpostcssconfigurablechecklimitedcallbreakvestlistenersoptimisturlsansiSetsyntaxerrorelectronbrowserslistisIteratorcommandassertiontoolsawaitenderupstringifierRxJSredux-toolkitslotES2015cloudsearchfastcopycjkconfigredactbrowserlistes2017cssobjfunctionaljsdiff0functiontakemkdirpreduceres2016patchcoerciblereact-hook-formECMAScript 2016lessdatees-shim APIextensionsharedtc39autoscalingrangeerrordeleteclassnamevpcregexpl10nreactdebuggersettingskarmaCSSStyleDeclarationsinatrafindLastIndexchromeincludesjQueryArray.prototype.flatlastcolorfast-copyextendUnderscoreSymbolescapesymbolsArray.prototype.flatMapflagsafeeventsfindprotoreact-testing-libraryidtddwindowsiteratorsidepreprocessoryamlmergeexitcss lessESwordbreakiampolyfillstylesheettermgetPrototypeOfYAMLnpmcomparematchesjsasyncdayjswarningworkeroutputswfcopycallboundJSON-Schemapipedefaultdynamodbcall-bindsymlinkES7weaksetObject.fromEntriesglobtapeventEmittertyped arraysharedarraybufferpropertiesgradients cssclass-validatorisConcatSpreadablegroupBycallbindmochaduplexArray.prototype.findLastuninstalldirqueryhigher-ordercryptparsejapaneseforEachstartersymlinksdeepcopyautoprefixerkeyshebangCSSemojiqsjasminepredictablehandlersPromisecreateavaroute53readablestreamSymbol.toStringTagless mixinsappconsolenametypedparserlibphonenumbertoArrayrdsargparselockfileargumentsmonorepottykeysdirectorycloudfrontkinesiswidthbusyinterruptsstdlibfastifyargumentinternal slotdeep-clonerequirees-abstractawsvariables in csssortvisualeslint-pluginWeakMapperformantcompilerhookformfromset
1.0.0

1 year ago