1.1.3 • Published 6 years ago
@robelberhe/requester v1.1.3
Server side http client
Requester is a server side http client, used to make api calls from your own or third party api's. Requester is a easy, lightweight, minimal http client with 0 dependencies. you can use it in NodeJs applications.
@robelberhe/requester
(https://github.com/RobiBerhe/server-side-http-client)
installation
npm install @robelberhe/requster
Examples (http get requests)
here is an example which show how to send an http get request using requester
const requester = require('@robelberhe/requester');
requester.get("http://yoursite.com/api/endpoint")
.then((res)=>{
console.log("Data Retrieved...");
console.log(res.body);
}).catch((error)=>{
console.log("There seems to be some problem accessing the resource");
console.log(error.message);
// you can also get whatever the server may have sent instead by accessing error.data.
// console.log(error.data);
});
Examples (http post requests)
const requester = require('@robelberhe/requester');
requester.post("http://yoursite.com/endpoint",{userID:1})
.then((res)=>{
console.log(`status code: ${res.statusCode}`);
console.log("Data : ");
console.log(res.body);
}).catch((error)=>{
console.log(error);
// or error.data.
});