4.1.1 • Published 3 years ago

fishingrod v4.1.1

Weekly downloads
103
License
MIT
Repository
-
Last release
3 years ago

fishingrod

A simple module for making http requests, depends on nothing but http and https.

NOTE: this is not intended to be a full-featured http package, or a full-tested module. This is a simple, working http module, that permits very simple requests. Do not use in production without testing.

Simple Example

const fishingrod = require('fishingrod');

fishingrod.fish({
	https:true,
	host: 'example.com',
	path: '/obj/1'
},
function(err, st, res){
	console.log(res);
});

fishingrod.fish({
	https:true,
	host: 'example.com',
	path: '/obj/2'
}).then(function(res){
	console.log(res.response);
});

API

fishingrod works in a very simple way using different parameters. A simple request will typically use https, host, path, method and data & headers if needed.

Some more parameters are also available if you would ever need them, and direct url pasting (request style) is also applicable.

ParameterTypeDescription
httpsBooleanSets https: or http: as the protocol
methodStringSets the method for the request. All usual HTTP methods are accepted (GET, POST, PUT, DELETE ...). MUST BE uppercase
hostStringThe host for the request. Ex: api.google.com
pathStringThe path for the request. Ex /api/v3.0/something?this=is&a=query (Query is optional, but for POST requests it won't be extracted from data)
dataString or ObjectThe data to send to the server. If the data is an object, it will be JSON.stringifyed for you.
headersObjectA collection of headers for the request. Ex: {'Content-Type':'application/json', 'X-My-Header': 'something custom'}
parseBooleanIf the response contains header Content-Type: application/json it will be JSON.parsed before giving you control of the answer
redirBooleanIf the response is a 3xx Http code and contains Location: header, will automatically redirect before giving you control
encodingStringSets the encoding for the response. Default is 'utf8'
debugBooleanSets the debug option, logging errors and every request
joinCharIf using Object Data && Content-Type: application/x-www-form-urlencoded, will be used as the join char between key-value pairs. Ex: plep=56${join}plop=57
separatorCharIf using Object Data && Content-Type: application/x-www-form-urlencoded, will be used as the join char between each key and its value. Ex: plop${separator}56

Utility methods

You can also call fishingrod with only a url using the utility methods. These are .get, .post, .put, .delete, ._method. They all take (url [STRING], data[OBJECT], headers[OBJECT]) as params, except _method which takes (method, [STRING CAPITALS], url [STRING], data[OBJECT], headers[OBJECT]).

const fishingrod = require('fishingrod');

fishingrod.get('http://google.com', {query:'Bottomatik chatbots'}, {'Accept':'application/pdf'});
4.1.1

3 years ago

4.1.0

5 years ago

4.0.0

6 years ago

3.9.5

6 years ago

3.9.0

7 years ago

3.7.5

7 years ago

3.7.0

7 years ago

3.6.5

7 years ago

3.6.0

7 years ago

3.5.5

7 years ago

3.5.0

7 years ago

3.4.0

7 years ago

3.3.0

7 years ago

3.2.0

7 years ago

3.1.0

7 years ago

3.0.0

7 years ago

2.8.5

7 years ago

2.8.0

7 years ago

2.7.0

7 years ago

2.6.0

8 years ago

2.5.0

8 years ago

2.4.0

8 years ago

2.3.0

8 years ago

2.2.0

8 years ago

2.1.0

8 years ago

2.0.0

8 years ago

1.9.0

8 years ago

1.8.0

8 years ago

1.7.0

8 years ago

1.6.0

8 years ago

1.5.1

8 years ago

1.5.0

8 years ago

1.4.9

8 years ago

1.4.8

8 years ago

1.4.7

8 years ago

1.4.5

8 years ago

1.4.0

8 years ago

1.3.0

8 years ago

1.2.0

8 years ago

1.1.0

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago