1.5.0 • Published 11 months ago

io v1.5.0

Weekly downloads
366
License
MIT
Repository
-
Last release
11 months ago

io

io is a simple Node.js HTTP wrapper for API calls.

Methods supported are...

const io = require('io');

io.request(method, url, queryParams = {}, headers = null, body = null);
io.get(url, authorization = null, headers = null, queryParams = {});
io.del(url, authorization = null, headers = null, queryParams = {});
io.post(url, authorization = null, headers = null, params = {});
io.put(url, authorization = null, headers = null, params = {});

All requests return a Promise and can be run synchronously using await.

let result = await io.request(method, url, queryParams = {}, headers = null, body = null);

request

The request method takes a raw body string and sends no content-type by default.

It returns a result with the following schema;

{
  "statusCode": 200,
  "headers": {},
  "body": ""
}

get, del

The get and del methods will populate the URL querystring with x-www-urlencoded values based on a queryParams object. They will send a content-type: application/json header by default.

The authorization parameter will set the authorization HTTP header. If this value begins with the strings Basic or Bearer, the full value will be used. Otherwise, Bearer will be prepended. Sending authorization = "x", for example, will populate the authorization header with a value of Bearer x.

NOTE: If the requested resource does not return JSON data, an error will be thrown.

They return a result with the following schema;

{
  "statusCode": 200,
  "headers": {},
  "data": {}
}

post, put

The post and put methods will populate the post body with application/json values based on a params object. They will send a content-type: application/json header by default.

The authorization parameter will set the authorization HTTP header. If this value begins with the strings Basic or Bearer, the full value will be used. Otherwise, Bearer will be prepended. Sending authorization = "x", for example, will populate the authorization header with a value of Bearer x.

NOTE: If the requested resource does not return JSON data, an error will be thrown.

They return a result with the following schema;

{
  "statusCode": 200,
  "headers": {},
  "data": {}
}

Thanks!

© 2020 Standard Library (Polybit Inc.)

1.5.0

11 months ago

1.4.1

12 months ago

1.4.0

12 months ago

1.2.0

1 year ago

1.3.2

1 year ago

1.3.1

1 year ago

1.3.0

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.1.3

1 year ago

1.1.2

1 year ago

1.0.5

2 years ago

1.0.4

3 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

6 years ago

0.1.10

8 years ago

0.1.9

8 years ago

0.1.8

8 years ago

0.1.7

8 years ago

0.0.9

9 years ago

0.0.8

9 years ago

0.0.7

9 years ago

0.0.6

9 years ago

0.0.5

9 years ago

0.0.4

9 years ago

0.0.3

9 years ago

0.0.2

9 years ago

0.0.1

9 years ago

0.1.6

13 years ago

0.1.5

13 years ago

0.1.3

13 years ago

0.1.2

13 years ago

0.1.1

13 years ago

0.1.0

13 years ago