2.1.3 • Published 7 years ago

@swlkr/req v2.1.3

Weekly downloads
1
License
MIT
Repository
github
Last release
7 years ago

req

Zero dependency json http client for the browser

Install

$ yarn add @swlkr/req

Use

import Http from "@swlkr/req";

// Get request
Http
.send({ url: "http://your-api.com/some-url", method: "get" })
.then(res => console.log(res))
.catch(err => console.log(err))

// Post request
Http
.send({ url: "http://your-api.com/some-url", body: { prop: "value", prop1: "value1", prop2: "value2" }, method: "POST" })
.then(res => console.log(res))
.catch(err => console.log(err))

// Custom headers with delete request
Http
.send({ url: "http://your-api.com/some-url", method: "delete", headers: { Authorization: "super secure json web token" } })
.then(res => console.log(res))
.catch(err => console.log(err))

// Using async/await
try {
  const response = await Http.send({ url: "http://your-api.com/some-url", method: "get" });
  // use response
} catch(error) {
  console.log(error.message);
  console.log(error.status);
}

// Handling the unfortunate event of a timeout
// timeout should be an integer that represents milliseconds
Http
.send({ url: "http://your-api.com/some-url", method: "GET", timeout: 1000 })
.then(res => console.log(res))
.catch(err => console.log(err))

Test

yarn
yarn test
2.1.3

7 years ago

2.1.2

8 years ago

2.1.1

8 years ago

2.1.0

8 years ago

2.0.1

8 years ago

2.0.0

8 years ago

1.0.0

8 years ago