0.0.7 • Published 4 years ago

lightpath v0.0.7

Weekly downloads
4
License
ISC
Repository
github
Last release
4 years ago

LightPath

Another Browser based HTTP request wrapper.

Why?

  • Promise Based
  • Supports Async Await
  • Less opinonated than axios
  • Easy Error handling

Install

<script src="https://cdn.jsdelivr.net/gh/jakeoverall/lightpath/dist/ligthpath.browser.min.js"></script>
> npm i lightpath

Usage

import LightPath from "lightpath";

// Create Instances
let api = new LightPath({
  baseURL: "http://localhost:5000",
  timeout: 8000,
  headers: { authorization: "Bearer token" },
  query: "?api_key=1234567"
});

async function testGetInstance(url) {
  try {
    await api.get(url);
  } catch (e) {
    console.log(e);
  }
}

// Or use directly
async function testGet(url) {
  try {
    await LightPath.get(url);
  } catch (e) {
    console.log(e);
  }
}

Error Types

class RequestError extends Error {
  constructor(msg, response, body = {}) {
    super(msg);
    this.response = response;
    this.status = response.status;
    this.body = body;
  }
}

class RequestTimeout extends Error {
  constructor(msg, url) {
    super(msg);
    this.url = url;
  }
}

Configure Instance Options

let instance = new LightPath({
  baseURL = "",
  headers = {},
  query = "",
  timeout = 8000,
  onRequest = (url, options) => {},
  onComplete = data => {},
  onError = err => {}
})
0.0.7

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago