Light-HTTP is a very light library. the purpose of this package is to easily make a http & https request, it also support asynchronous and synchonrous(promise) request at the same time. You can use this library on Node.js environment and any version of Browser such as IE8 ~, Chrome, Firefox.
The following example will show you how to use light-http on Node.js environment.
npm install light-http
There are some examples here.
var http = require('light-http'); var header = {"user-agent": "Mozilla/5.0 xx"}; var url = "https://www.google.com.tw"; // Method GET http.get(url, {"key":"value"}, header, function(response) { xxx }); // Method POST http.post(url, {"key":"value"}, header, function(response) { xxx });
var http = require('light-http'); var header = {"user-agent": "Mozilla/5.0 xx"}; var url = "https://www.google.com.tw"; // Method GET http.get(url, {"key":"value"}, header) .then(function(response) { xxx }); // Method POST http.post(url, {"key":"value"}, header) .then(function(response) { xxx });
var http = require('light-http'); var header = {"user-agent": "Mozilla/5.0 xx"}; var url = "https://www.google.com.tw"; http.addFile("fileData", "/www/var/file.txt"); http.addFileContent("fileData", "file.txt", "content"); http.post(url, {"key":"value"}, header) .then(function(response) { xxx });
var http = require('light-http'); var host = "www.google.com.tw"; var port = 80; var path = "/"; var cookie = 'SID=; HSID=; SSID=jjj; APISID=;'; var msg = [ "GET " + path + " HTTP/1.1", "host: " + host, "cookie: " + cookie, "\r\n"].join("\r\n"); http.rawRequest(host, port, msg) .then(function (resp) { console.log(resp); });