Comparing version 0.0.4 to 0.0.5
# Changelog | ||
All notable changes to this project will be documented in this file. | ||
## [0.0.5] - 2020-08-16 | ||
### Changed | ||
- Forks now return another Ira instance | ||
### Fixed | ||
- All `.blob, .text, .json` responses are provided now | ||
## [0.0.4-beta0.2] - 2020-08-16 | ||
### Added | ||
- Minified version - really added, comments kept : ) | ||
- **Now you can .extend.extend.extend.... Ira's:** Keep in mind that from a `.extend` function prop `._config` will return config provided on function call. | ||
### Changed | ||
- Custom function export has been replaced | ||
### Fixed | ||
- Removed string version of Blob if it's text type or type's undefined | ||
## [0.0.4-beta0.1] - 2020-08-15 | ||
### Added | ||
- You can now parse blob to base64 - `ira.blobToBase64` | ||
### Fixed | ||
- Now user wont get utf-8 version of binary inside data.blob | ||
### Removed | ||
- `.reset() method` , you can use `ira.config({})` | ||
## [0.0.4] - 2020-08-13 | ||
### Added | ||
- Params can be passed from request: `ira.get("/", { params: { } })` | ||
@@ -10,3 +52,3 @@ - This log was created | ||
### Changed | ||
- Root const's were changed to var | ||
{ | ||
"name": "irajs", | ||
"version": "0.0.4", | ||
"description": "Ira Fetch - Vanilla JS Fetch API wrapper with goodies 🍒", | ||
"main": "src/index.js", | ||
"version": "0.0.5", | ||
"description": "Ira - Vanilla JS Fetch API wrapper with goodies 🍒", | ||
"main": "src/index.min.js", | ||
"repository": { | ||
@@ -10,8 +10,12 @@ "type": "git", | ||
}, | ||
"scripts": { | ||
"minify": "terser src/index.js -o src/index.min.js --comments=all && src/superformat.sh", | ||
"start": "yarn minify && node tests/serve" | ||
}, | ||
"keywords": [ | ||
"fetch", | ||
"wrapper", | ||
"fetch-api", | ||
"browser", | ||
"request" | ||
"request", | ||
"http" | ||
], | ||
@@ -23,3 +27,6 @@ "author": "Denny Portillo <d3portillo@gmail.com>", | ||
}, | ||
"homepage": "https://github.com/D3Portillo/ira#readme" | ||
"homepage": "https://d3portillo.github.io/ira/", | ||
"devDependencies": { | ||
"terser": "^5.1.0" | ||
} | ||
} |
170
README.md
@@ -1,10 +0,24 @@ | ||
# Ira Fetch Wrapper | ||
<p align="center"> | ||
<a href="https://d3portillo.github.io/ira/"> | ||
<img width="420" src="./assets/ira.svg"/> | ||
</a> | ||
</p> | ||
--- | ||
<strong> | ||
<a href="https://codepen.io/D3Portillo/pen/poyjxwM">📝 Codepen</a> ・ | ||
<a href="https://observablehq.com/@d3portillo/ira-fetch-wrapper">🔬 Observable</a> ・ | ||
<a href="https://www.npmjs.com/package/irajs">📦 Npm</a> | ||
</strong> | ||
--- | ||
**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 for requesting functions with a set of settings. | ||
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 intends to be writtend just using current JS engine features, no babel or typescript used. It's plain vanilla Javascript. | ||
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 | ||
@@ -21,44 +35,38 @@ ``` | ||
## CDN | ||
## CDN Load | ||
```html | ||
<script src="https://d3portillo.github.io/ira/src/index.js"></script> | ||
<script src="https://d3portillo.github.io/ira/src/index.min.js"></script> | ||
``` | ||
Long live to Github Pages : ) | ||
## Usage | ||
```js | ||
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 | ||
### GET Method | ||
```js | ||
ira.get(`https://postman-echo.com/get?foo1=bar1&foo2=bar2`).then(({ data }) => { | ||
console.log(data.json, data.text, data.blob) | ||
// * Automatic response parsing | ||
/* | ||
You can do it also parsing params as | ||
ira.get(URL, { params: { foo1: "bar1", foo2: "bar2" } }) | ||
*/ | ||
console.log(data.json, data.text, data.blob) // * Automatic response parsing | ||
}) | ||
``` | ||
### POST | ||
```js | ||
ira | ||
.post(`https://postman-echo.com/post`, { | ||
body: "This body will be returned", | ||
}) | ||
.then(({ data }) => { | ||
console.log(data.json, data.text, data.blob) | ||
// Automatic response parsing | ||
}) | ||
``` | ||
### Set global headers | ||
Usefull if doing different request with auth stuff | ||
- Set all request to `application/json` Content-Type | ||
```js | ||
@@ -72,32 +80,23 @@ ira.config({ | ||
- Now, all your requests will include those headers | ||
### Parse blob to base64 | ||
```js | ||
ira.get("https://something").then(console.info) | ||
const blob = new Blob(["something"]) | ||
ira.blobToBase64(blob).then((base64) => console.log(base64)) | ||
``` | ||
### Extend a Ira fork | ||
### Base URL | ||
A custom settings fork of main Ira function that's gapped to provided - config | ||
- Set _debug_ mode | ||
```js | ||
const nfetch = ira.extend({ | ||
headers: { | ||
"Content-type": "application/json", | ||
}, | ||
debug: true, | ||
parseBlob: false /* Do not include .blob body response */, | ||
const request = ira.extend({ | ||
baseURL: "https://yourendpoint.com/dev/branch", | ||
}) | ||
// Now you can do | ||
request.get("/binary") //https://yourendpoint.com/dev/branch/binary | ||
``` | ||
- You can now fetch data with those settings | ||
### Extend Ira fork | ||
```js | ||
nfetch.get("https://something").then(({ blob }) => console.info(null == blob)) | ||
``` | ||
A custom settings fork of main Ira function that's gapped to provided - config | ||
- Fetching with keys and session that contain same config | ||
```js | ||
@@ -108,11 +107,11 @@ const request = ira.extend({ | ||
}, | ||
debug: true /* Show Ira stuff on console */, | ||
baseURL: "https://someendpoint" | ||
parseBlob: false /* Do not include .blob body response */ | ||
debug: true /* Shows Ira stuff on console */, | ||
parseBlob: false /* Do not include .blob on data */, | ||
}) | ||
request.get("/stuff").then(({ data })=> console.log({ data })) | ||
request.get("/post", { headers: { "a-header": "a-value" } }).then(({ data })=>{ | ||
console.log({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 | ||
``` | ||
@@ -122,6 +121,4 @@ | ||
URL/?yourparams=avalue | ||
```js | ||
ira.get(`anendpoint`, { | ||
ira.get("https://anendpoint", { | ||
params: { | ||
@@ -132,9 +129,9 @@ token: 222, | ||
}) | ||
// http://anendpoint/?token=222&another-token=354 | ||
// https://anendpoint/?token=222&another-token=354 | ||
``` | ||
## Ira Object instances | ||
## The Ira Instance | ||
```js | ||
IRA_RESPONSE = { | ||
RESPONSE = { | ||
data: { json: Object, text: String, blob: ?Blob } | ||
@@ -145,12 +142,12 @@ ok: Boolean, | ||
statusCode: status<Number>, | ||
error:?Error | ||
error: ?Error | ||
} | ||
IRA_REQUEST_PROPS = { | ||
ON_REQUEST_PROPS = { | ||
headers: {}, | ||
body: ?String, | ||
...({ | ||
Request:`https://developer.mozilla.org/en-US/docs/Web/API/Request` | ||
}) | ||
debug: ?Boolean, | ||
parseBlob: ?Boolean, | ||
...`https://developer.mozilla.org/en-US/docs/Web/API/Request` | ||
} | ||
IRA_SETTINGS = { | ||
GLOBAL_SETTINGS = { | ||
headers: {}, | ||
@@ -161,3 +158,3 @@ debug: Boolean, | ||
} | ||
IRA_HTTP_METHODS = { | ||
HTTP_METHODS = { | ||
get: Function, | ||
@@ -173,3 +170,3 @@ put: Function, | ||
// Exported object {Main} | ||
// Exported object { Main } | ||
ira = { | ||
@@ -179,33 +176,16 @@ ...IRA_HTTP_METHODS, | ||
_settings: Object, | ||
reset: Function, | ||
config: Function, | ||
extend: IRA_HTTP_METHODS | ||
extend: Function() => ira /* Fork with provided settings */, | ||
blobToBase64: Function | ||
} | ||
``` | ||
| Name/Instance | Params ? | Returns | Comments | | ||
| ---------------- | --------------------------- | ----------------------- | ---------------------------------------------------------------------- | | ||
| IRA_HTTP_METHODS | (`URL`,`IRA_REQUEST_PROPS`) | `Promise<IRA_RESPONSE>` | Fetch API HTTP Methods | | ||
| default() | (`URL`,`IRA_REQUEST_PROPS`) | `Promise<IRA_RESPONSE>` | When you do Ira("URL") | | ||
| \_settings | `NONE` | `Void` | Acces current Ira global settings | | ||
| reset() | `NONE` | `Void` | Resets persistence settings to default | | ||
| config() | `IRA_SETTINGS` | `Void` | Set ira settings (This affects all requests) | | ||
| extend() | `IRA_SETTINGS` | `IRA_HTTP_METHODS` | Returns a fork of Ira with just HTTP Methods and provided Ira Settings | | ||
Ira will return a void response if an error ocurred and status of 500. | ||
Ira will return a void response if an error ocurred and status of 500, | ||
I'm currently working on a way of returning status on error | ||
--- | ||
> **Ira** stands for: Go to, rage or anger. That's all the feelings you have while handling HTTP stuff : ) | ||
- Source: [/src/index.js](./src/index.js) | ||
- Changelog: [/CHANGELOG.md](./CHANGELOG.md) | ||
- License: [/LICENSE](./LICENSE) | ||
- Source: [./src/index.js](./src/index.js) | ||
- Changelog: [./CHANGELOG.md](./CHANGELOG.md) | ||
--- | ||
## TODO | ||
- [ ] Unit tests | ||
- [ ] Some custom examples | ||
- [ ] Live examples on Codepen or similar | ||
> **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 : ) |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
11705
1
5
62
183
3