1.1.1 • Published 6 months ago

@redmunroe/sling v1.1.1

Weekly downloads
-
License
ISC
Repository
-
Last release
6 months ago

Sling

sling inspired by https://github.com/dghubble/sling

Install

npm i @redmunroe/sling

Import

import sling from '@redmunroe/sling';

Usage

successful request 2XX

type success = {
    field : string
}
const s = new sling({
  host: "api.somedomain.com",
  headers: {
    "Content-Type": "application/json"
  };
})
const response = await s.path("/some/resource").get().successJSON<success>();
if (!response) {
    throw new Error("some error occurred");
}
console.log(response);

failure anything not 2XX

type failure = {
    field : string
}
const s = new sling({
  host: "api.somedomain.com",
  headers: {
    "Content-Type": "application/json"
  };
})
const response = await s.path("/some/resource").get().failureJSON<failure>();
if (!response) {
    throw new Error("some error occurred");
}
console.log(response);

get either success or failure at the same time.

type success = {
    field: string
}

type failure = {
    field : string
}
const s = new sling({
  host: "api.somedomain.com",
  headers: {
    "Content-Type": "application/json"
  };
})
const response = await s.path("/some/resource").get().request<success, failure>();

console.log(response.success);
console.log(response.failure);
1.1.1

6 months ago

1.2.0

10 months ago

1.1.0

10 months ago

1.0.2

11 months ago

1.0.1

11 months ago

1.0.0

11 months ago