{"id":27177503,"url":"https://github.com/d3portillo/ira","last_synced_at":"2025-04-09T13:57:53.618Z","repository":{"id":57276751,"uuid":"286878263","full_name":"D3Portillo/ira","owner":"D3Portillo","description":"Vanilla JS Fetch API wrapper with goodies 🍒","archived":false,"fork":false,"pushed_at":"2020-09-13T23:54:44.000Z","size":134,"stargazers_count":4,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-04T18:55:58.450Z","etag":null,"topics":["fetch","fetch-api","http","http-requests","ira","requests"],"latest_commit_sha":null,"homepage":"https://d3portillo.github.io/ira","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/D3Portillo.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-08-12T00:36:41.000Z","updated_at":"2022-03-23T14:55:37.000Z","dependencies_parsed_at":"2022-09-15T19:10:31.985Z","dependency_job_id":null,"html_url":"https://github.com/D3Portillo/ira","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/D3Portillo%2Fira","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/D3Portillo%2Fira/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/D3Portillo%2Fira/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/D3Portillo%2Fira/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/D3Portillo","download_url":"https://codeload.github.com/D3Portillo/ira/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248054218,"owners_count":21039951,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fetch","fetch-api","http","http-requests","ira","requests"],"created_at":"2025-04-09T13:57:52.791Z","updated_at":"2025-04-09T13:57:53.592Z","avatar_url":"https://github.com/D3Portillo.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://d3portillo.github.io/ira/\"\u003e\n    \u003cimg width=\"420\" src=\"./assets/ira.svg\"/\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n---\n\n  \u003cstrong\u003e\n  \u003ca href=\"https://codepen.io/D3Portillo/pen/poyjxwM\"\u003e📝 Codepen\u003c/a\u003e ・\n  \u003ca href=\"https://observablehq.com/@d3portillo/ira-fetch-wrapper\"\u003e🔬 Observable\u003c/a\u003e ・\n  \u003ca href=\"https://www.npmjs.com/package/irajs\"\u003e📦 Npm\u003c/a\u003e\n  \u003c/strong\u003e\n\n---\n\n**Ira Fetch:** Vanilla JS Fetch API wrapper with goodies 🍒\n\nIrajs is a **small ~ 3kb** function which enhances current Fetch API with more, more goodies. Ira code isn't chopped, replaced with random chars or similar on .min.js version, it's just minified.\n\nIra goodies include debug logs, persistent settings and custom currying to request functions with a set of options. The little wrapper tries to function using current JS Engine features, no babel or typescript used just plain vanilla Javascript.\n\n![Version](https://img.shields.io/npm/v/irajs/latest)\n![Size](https://img.shields.io/bundlephobia/minzip/irajs)\n![Downloads](https://img.shields.io/npm/dw/irajs)\n\n## Npm Install\n\n```\nnpm install irajs\n```\n\n## Yarn Install\n\n```\nyarn add irajs\n```\n\n## CDN Load\n\n```html\n\u003cscript src=\"https://d3portillo.github.io/ira/src/index.min.js\"\u003e\u003c/script\u003e\n```\n\n## Usage\n\n```js\nimport ira from \"irajs\"\n// Requires\nconst ira = require(\"irajs\")\n// Start playing around\nira.get(\"/stuff\")\n```\n\n[👉 The complete API reference](#Ira-API-Reference)\n\n## Some examples\n\n### Getting data\n\n```js\nira.get(`https://postman-echo.com/get?foo1=bar1\u0026foo2=bar2`).then(({ data }) =\u003e {\n  console.log(data.json, data.text, data.blob) // * Automatic response parsing\n})\n```\n\n### Adding headers\n\n```js\nira.config({\n  headers: {\n    \"Content-type\": \"application/json\",\n  },\n})\n```\n\n### Parsing blob to base64 string\n\n```js\nconst blob = new Blob([\"something\"])\nira.blobToBase64(blob).then((base64) =\u003e console.log(base64))\n```\n\n### Including a base URL\n\n```js\nconst request = ira.extend({\n  baseURL: \"https://yourendpoint.com/dev/branch\",\n})\n// Now you can do\nrequest.get(\"/binary\") //https://yourendpoint.com/dev/branch/binary\n```\n\n### Extending a fork\n\nA custom settings fork of main Ira function that's gapped to provided - config\n\n```js\nconst request = ira.extend({\n  headers: {\n    \"x-api-key\": \"somsaltedencryptedawesomekey\",\n  },\n  debug: true /* Shows Ira stuff on console */,\n  parseBlob: false /* Do not include .blob on data */,\n})\n\n// Now you can make requests containing those settings\nrequest\n  .get(\"https://something\")\n  .then(({ data: { blob } }) =\u003e console.info(null == blob))\n// The blob response inside data obj is null\n```\n\n\u003e This method extends from Ira Object\n\n## The Ira Instance\n\n```js\nRESPONSE = {\n  data: { json: Object, text: String, blob: ?Blob }\n  ok: Boolean,\n  status: Number,\n  statusText: String,\n  statusCode: status\u003cNumber\u003e,\n  error: ?Error\n}\nON_REQUEST_PROPS = {\n  headers: {},\n  body: ?String,\n  debug: ?Boolean,\n  parseBlob: ?Boolean,\n  params: {},\n  ...`https://developer.mozilla.org/en-US/docs/Web/API/Request`\n}\nIRA_SETTINGS = {\n  headers: {},\n  debug: Boolean,\n  parseBlob: Boolean,\n  baseURL: ?String,\n}\nHTTP_METHODS = {\n  get: Function,\n  put: Function,\n  post: Function,\n  head: Function,\n  delete: Function,\n  connect: Function,\n  options: Function,\n  trace: Function,\n}\n\n// Exported object { Main }\nira = {\n  ...HTTP_METHODS,\n  default(): HTTP_METHODS.get,\n  _settings: Object,\n  config: Function,\n  extend: Function() =\u003e ira /* Fork with provided config */,\n  blobToBase64: Function\n}\n```\n\nIra will return a void response if an error ocurred and status of 500.\n\n## Ira API Reference\n\n### Table of contents\n\n- [ira()](#default)\n- [ira.get()](#get)\n- [ira.post()](#post)\n- [ira.put()](#post)\n- [ira.delete()](#delete)\n- [ira.connect()](#connect)\n- [ira.options()](#options)\n- [ira.trace()](#trace)\n- [ira.head()](#head)\n- [ira.blobToBase64()](#blobtobase64)\n- [ira.on()](#onevent)\n- [ira.extend()](#extend)\n- [ira.config()](#config)\n- [ira.\\_config](#getconfig)\n- [{ baseURL }](#baseurl)\n- [{ params }](#params)\n- [{ debug }](#debug)\n- [{ parseBlob }](#parseblob)\n\n### HTTP Methods\n\nThis interface rules among many props and methods, **`ON_REQUEST_PROPS:` [ira#the-ira-instance](https://github.com/D3Portillo/ira#the-ira-instance)**\n\n---\n\n\u003ca href=\"#default\" id=\"default\"\u003e# \u003c/a\u003e\u003cb\u003eira\u003c/b\u003e([\u003ci\u003eURL, CONFIG\u003c/i\u003e]) [\u003c\u003e](https://github.com/D3Portillo/ira/blob/master/src/index.js#L41 \"Source\")\n\n```js\nURL = \"\" // Your endpoint URL\nCONFIG = ON_REQUEST_PROPS\n```\n\nThe GET method, `ira(\"/something\")` is the same as `fetch(\"/something\")`. The difference is ira.get returns a `Promise` which resolves to an Object including .json, .text and .blob methods.\n\n`ira().then(({data}) =\u003e { data.json | data.text | data.blob })`\n\n\u003ca href=\"#get\" id=\"get\"\u003e# \u003c/a\u003eira\u003cb\u003e.get\u003c/b\u003e([\u003ci\u003eURL, CONFIG\u003c/i\u003e]) [\u003c\u003e](https://github.com/D3Portillo/ira/blob/master/src/index.js#L169 \"Source\")\n\n```js\nURL = \"\" // That stuff URL\nCONFIG = ON_REQUEST_PROPS\n```\n\nSame as `ira()` method.\n\n\u003ca href=\"#post\" id=\"post\"\u003e# \u003c/a\u003eira\u003cb\u003e.post\u003c/b\u003e([\u003ci\u003eURL, CONFIG\u003c/i\u003e]) [\u003c\u003e](https://github.com/D3Portillo/ira/blob/master/src/index.js#L178 \"Source\")\n\n```js\nURL = \"\" // An endpoint\nCONFIG = ON_REQUEST_PROPS\n```\n\nThe POST method, `ira.post(\"/something\")` is the same as `fetch(\"/something\", { method: \"POST\" })`.\n\nYou can include a body doing:\n\n```js\nira.post(\"/something\", {\n  body: \"some-body\",\n})\n```\n\n\u003ca href=\"#put\" id=\"put\"\u003e# \u003c/a\u003eira\u003cb\u003e.put\u003c/b\u003e([\u003ci\u003eURL, CONFIG\u003c/i\u003e]) [\u003c\u003e](https://github.com/D3Portillo/ira/blob/master/src/index.js#L179 \"Source\")\n\n```js\nURL = \"\" // https://something\nCONFIG = ON_REQUEST_PROPS\n```\n\nThe HTTP PUT method, `ira.put(\"/api\")` is the same as `fetch(\"/api\", { method: \"PUT\" })`.\n\nYou can include a body doing:\n\n```js\nira.put(\"/something\", {\n  body: \"some-body\",\n})\n```\n\nYou also can show some debug messages on console by adding `debug: true`.\n\n```js\nira.put(\"/something\", {\n  body: \"some-body\",\n  debug: true,\n})\n\n// This will log on request start messages and\n// When promise is resolved with your data\n```\n\n\u003ca href=\"#delete\" id=\"delete\"\u003e# \u003c/a\u003eira\u003cb\u003e.delete\u003c/b\u003e([\u003ci\u003eURL, CONFIG\u003c/i\u003e]) [\u003c\u003e](https://github.com/D3Portillo/ira/blob/master/src/index.js#L175 \"Source\")\n\n```js\nURL = \"\" // Place an URL here\nCONFIG = ON_REQUEST_PROPS\n```\n\nThat DELETE Http Method, `ira.delete(\"/api\")` is the same as `fetch(\"/api\", { method: \"DELETE\" })`.\n\n\u003ca href=\"#connect\" id=\"connect\"\u003e# \u003c/a\u003eira\u003cb\u003e.connect\u003c/b\u003e([\u003ci\u003eURL, CONFIG\u003c/i\u003e]) [\u003c\u003e](https://github.com/D3Portillo/ira/blob/master/src/index.js#L180 \"Source\")\n\n```js\nURL = \"\" // The place you want data from\nCONFIG = ON_REQUEST_PROPS\n```\n\nDoin a CONNECT method `ira.connect(\"/api\")` is same as `fetch(\"/api\", { method: \"CONNECT\" })`.\n\nYou can include this config on your request:\n\n```js\n{\n  headers: {}, // Your request headers\n  body: ?String, // Your request body\n  debug: ?Boolean, // if true shows some stuff on console\n  parseBlob: ?Boolean, // if false .blob event wont execute\n  params: {} // Your URL params ?reqid=3\u0026something=data\n}\n```\n\n\u003ca href=\"#options\" id=\"options\"\u003e# \u003c/a\u003eira\u003cb\u003e.options\u003c/b\u003e([\u003ci\u003eURL, CONFIG\u003c/i\u003e]) [\u003c\u003e](https://github.com/D3Portillo/ira/blob/master/src/index.js#L181 \"Source\")\n\n```js\nURL = \"\" // That URL you want data from\nCONFIG = ON_REQUEST_PROPS\n```\n\nWhen doing the OPTIONS Http method `ira.options(\"/api\")` results to be same as doing `fetch(\"/api\", { method: \"OPTIONS\" })`.\n\n\u003ca href=\"#trace\" id=\"trace\"\u003e# \u003c/a\u003eira\u003cb\u003e.trace\u003c/b\u003e([\u003ci\u003eURL, CONFIG\u003c/i\u003e]) [\u003c\u003e](https://github.com/D3Portillo/ira/blob/master/src/index.js#L41 \"Source\")\n\n```js\nURL = \"\" // Production or dev endpoint\nCONFIG = ON_REQUEST_PROPS\n```\n\nTRACE method, `ira.trace(\"/api\")` is the same as `fetch(\"/api\", { method: \"TRACE\" })`.\n\n\u003ca href=\"#head\" id=\"head\"\u003e# \u003c/a\u003eira\u003cb\u003e.head\u003c/b\u003e([\u003ci\u003eURL, CONFIG\u003c/i\u003e]) [\u003c\u003e](https://github.com/D3Portillo/ira/blob/master/src/index.js#L182 \"Source\")\n\n```js\nURL = \"\" // Some resource URL\nCONFIG = ON_REQUEST_PROPS\n```\n\nThe HEAD method, `ira.head(\"/api\")` is the same as `fetch(\"/api\", { method: \"HEAD\" })`.\n\n### Yes, more cool methods\n\n\u003ca href=\"#blobtobase64\" id=\"blobtobase64\"\u003e# \u003c/a\u003eira\u003cb\u003e.blobToBase64\u003c/b\u003e([\u003ci\u003eBlob\u003c/i\u003e]) [\u003c\u003e](https://github.com/D3Portillo/ira/blob/master/src/index.js#L207 \"Source\")\n\n```js\nBlob = new Blob() // A JS Binary long object\n```\n\nYou can parse any `Blob` into a base64 string by doing `ira.blobToBase64`. This returns a Promise which resolves into a String. This method will always resolve if there's an error check out you console. If Promise fails will resolve to `\"\"`\n\n\u003ca href=\"#onevent\" id=\"onevent\"\u003e# \u003c/a\u003eira\u003cb\u003e.on\u003c/b\u003e([\u003ci\u003eEvent\u003c/i\u003e]) [\u003c\u003e](https://github.com/D3Portillo/ira/blob/master/src/index.js#L233 \"Source\")\n\n```js\nEvent = \"request\" | \"response\"\n```\n\nYou can add a custom listener when ira or it's forks perform a request or when a response is succeded. You can set this triggers like this `ira.on(\"response\", callback)`.\n\nExample:\n\n```js\nira.on(\"request\", (request) =\u003e {\n  const { url, statusCode, method, headers, config } = request\n  if (statusCode == 200) {\n    console.log(\"This will always succeed\")\n    /*\n     This callback is made as soon as request is made\n     so statusCode is 200, you can log config, check path and include some magic\n    */\n  }\n})\n\nira.on(\"response\", (response) =\u003e {\n  const { url, statusCode, method, headers, config } = request\n  // Lets say you want to kick user when it's forbidden\n  if (statusCode == 403) killSession()\n})\n```\n\n\u003ca href=\"#extend\" id=\"extend\"\u003e# \u003c/a\u003eira\u003cb\u003e.extend\u003c/b\u003e([\u003ci\u003eCONFIG\u003c/i\u003e]) [\u003c\u003e](https://github.com/D3Portillo/ira/blob/master/src/index.js#L244 \"Source\")\n\n```js\nCONFIG = {\n  headers: {},\n  debug: Boolean,\n  parseBlob: Boolean,\n  baseURL: ?String,\n} // @see https://github.com/D3Portillo/ira#the-ira-instance\n```\n\nThis method returns a new Ira instance, you can replace default Settings with your custom ones. This can be helpfull if making request to API's where headers are somewhat \"persistent\", for example x-api-key's or that.\n\nExample:\n\n```js\nconst request = ira.extend({\n  headers: {\n    \"x-api-key\": \"somethingawesome\",\n    \"Content-type\": \"application/json\",\n  },\n})\n\n// Then you can avoid rewriting those headers again\n\nrequest.get(\"/endpoint\", {\n  body: {\n    user: \"D3Portillo\",\n    base: \"Somebass\",\n  },\n})\n// This will include those headers added on .extend call\n```\n\n\u003ca href=\"#config\" id=\"config\"\u003e# \u003c/a\u003eira\u003cb\u003e.config\u003c/b\u003e([\u003ci\u003eCONFIG\u003c/i\u003e]) [\u003c\u003e](https://github.com/D3Portillo/ira/blob/master/src/index.js#L194 \"Source\")\n\n```js\nCONFIG = {\n  headers: {},\n  debug: Boolean,\n  parseBlob: Boolean,\n  baseURL: ?String,\n} // @see https://github.com/D3Portillo/ira#the-ira-instance\n```\n\nThis method is used to replace current ira or fork settings. This replaces .extend method stuff with those new ones you provide.\n\n```js\nconst req = ira.extend({\n  baseURL: \"https://google.com\",\n})\n\n// Now, let's pretend you want to change that baseURL\nreq.settings({\n  baseURL: \"https://duckduckgo.com\",\n})\n// This will replace request's baseURL google.com with duckduck.go\n```\n\n### Acces current config\n\n\u003ca href=\"#getconfig\" id=\"getconfig\"\u003e# \u003c/a\u003eira\u003cb\u003e.\\_config\u003c/b\u003e\u003ci\u003e\\\u003cCONFIG\u003e\u003c/i\u003e [\u003c\u003e](https://github.com/D3Portillo/ira/blob/master/src/index.js#L188 \"Source\")\n\n```js\nCONFIG = {\n  headers: {},\n  debug: Boolean,\n  parseBlob: Boolean,\n  baseURL: ?String,\n} // @see https://github.com/D3Portillo/ira#the-ira-instance\n```\n\nIf you want to check current ira config do `ira._config`. This is supposed to be changed with `ira.config()`, still you can set `ira.\\_config.headers = {}`\n\n### Config[`._config`] props\n\n\u003ca href=\"#baseurl\" id=\"baseurl\"\u003e# \u003c/a\u003eira\u003cb\u003e.\\_config.baseURL\u003c/b\u003e\u003ci\u003e\\\u003cBoolean\u003e\u003c/i\u003e [\u003c\u003e](https://github.com/D3Portillo/ira/blob/master/src/index.js#L74 \"Source\")\n\nYou can add a baseURL to make your requests.\n\n```js\nira.settings({\n  baseURL: \"https://localhost:5000\",\n})\nira.get(\"/anurl\", {\n  params: {\n    somelikeparam: \"somevalue\",\n  },\n}) // Fetches https://localhost:5000/anurl\n```\n\n\u003ca href=\"#params\" id=\"params\"\u003e# \u003c/a\u003eira\u003cb\u003e.\\_config.params\u003c/b\u003e\u003ci\u003e\\\u003cObject\u003e\u003c/i\u003e [\u003c\u003e](https://github.com/D3Portillo/ira/blob/master/src/index.js#L76 \"Source\")\n\nYou can add params on your request like this:\n\n```js\nira.get(\"/anurl\", {\n  params: {\n    somelikeparam: \"somevalue\",\n  },\n}) // Fetches to /anurl?somelikeparam=somevalue\n```\n\n\u003ca href=\"#debug\" id=\"debug\"\u003e# \u003c/a\u003eira\u003cb\u003e.\\_config.debug\u003c/b\u003e\u003ci\u003e\\\u003cBoolean\u003e\u003c/i\u003e [\u003c\u003e](https://github.com/D3Portillo/ira/blob/master/src/index.js#L140 \"Source\")\n\nIf `true` will log stuff on console when a request is made and when a response is obtained.\n\n\u003ca href=\"#parseblob\" id=\"parseblob\"\u003e# \u003c/a\u003eira\u003cb\u003e.\\_config.parseBlob\u003c/b\u003e\u003ci\u003e\\\u003cBoolean\u003e\u003c/i\u003e [\u003c\u003e](https://github.com/D3Portillo/ira/blob/master/src/index.js#L105 \"Source\")\n\nIf `false` any request you make wont perform a **response.blob** and your data will resolve with this as `null`\n\n### Some resources\n\n- Source: [/src/index.js](./src/index.js)\n- Changelog: [/CHANGELOG.md](./CHANGELOG.md)\n- License: [/LICENSE](./LICENSE)\n\n---\n\n**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 : )\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fd3portillo%2Fira","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fd3portillo%2Fira","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fd3portillo%2Fira/lists"}