Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

irajs

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

irajs

Ira - Vanilla JS Fetch API wrapper with goodies 🍒

  • 0.0.5
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source


📝 Codepen🔬 Observable📦 Npm

Ira Fetch: Vanilla JS Fetch API wrapper with goodies 🍒

Ira is a window.fetch API wrapper with some extra stuff. Debug logs, persistent settings and custom currying to request functions with a set of options.

This little wrapper tries to function using current JS Engine features, no babel or typescript used. It's plain vanilla Javascript.

Npm Install

npm install --save irajs

Yarn Install

yarn add irajs

CDN Load

<script src="https://d3portillo.github.io/ira/src/index.min.js"></script>

Usage

import ira from "irajs"
// Requires
const ira = require("irajs")
// Start playing around
ira.get("/stuff")

Playground

Observable playground, live examples with the power of reactivity.

Recommended as start point

https://observablehq.com/@d3portillo/ira-fetch-wrapper

Examples

GET Method

ira.get(`https://postman-echo.com/get?foo1=bar1&foo2=bar2`).then(({ data }) => {
  console.log(data.json, data.text, data.blob) // * Automatic response parsing
})

Set global headers

ira.config({
  headers: {
    "Content-type": "application/json",
  },
})

Parse blob to base64

const blob = new Blob(["something"])
ira.blobToBase64(blob).then((base64) => console.log(base64))

Base URL

const request = ira.extend({
  baseURL: "https://yourendpoint.com/dev/branch",
})
// Now you can do
request.get("/binary") //https://yourendpoint.com/dev/branch/binary

Extend Ira fork

A custom settings fork of main Ira function that's gapped to provided - config

const request = ira.extend({
  headers: {
    "x-api-key": "somsaltedencryptedawesomekey",
  },
  debug: true /* Shows Ira stuff on console */,
  parseBlob: false /* Do not include .blob on data */,
})

// Now you can make requests containing those settings
request
  .get("https://something")
  .then(({ data: { blob } }) => console.info(null == blob))
// The blob response inside data obj is null

Fetching with params

ira.get("https://anendpoint", {
  params: {
    token: 222,
    "another-token": 354,
  },
})
// https://anendpoint/?token=222&another-token=354

The Ira Instance

RESPONSE = {
  data: { json: Object, text: String, blob: ?Blob }
  ok: Boolean,
  status: Number,
  statusText: String,
  statusCode: status<Number>,
  error: ?Error
}
ON_REQUEST_PROPS = {
  headers: {},
  body: ?String,
  debug: ?Boolean,
  parseBlob: ?Boolean,
  ...`https://developer.mozilla.org/en-US/docs/Web/API/Request`
}
GLOBAL_SETTINGS = {
  headers: {},
  debug: Boolean,
  parseBlob: Boolean,
  baseURL: ?String,
}
HTTP_METHODS = {
  get: Function,
  put: Function,
  post: Function,
  head: Function,
  delete: Function,
  connect: Function,
  options: Function,
  trace: Function,
}

// Exported object { Main }
ira = {
  ...IRA_HTTP_METHODS,
  default(): IRA_HTTP_METHODS.get,
  _settings: Object,
  config: Function,
  extend: Function() => ira /* Fork with provided settings */,
  blobToBase64: Function
}

Ira will return a void response if an error ocurred and status of 500.


Ira stands for: Go-to in spanish Ir-a. Can also mean rage or anger, That's all the feelings you have while handling HTTP stuff : )

Keywords

FAQs

Package last updated on 16 Aug 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc