Comparing version
var unirest = require('unirest') | ||
var harplayer = require('harplayer') | ||
var statusCodes = require('./codes.js') | ||
module.exports = function getStatus(url, cb) { | ||
module.exports = function getStatus(target, cb) { | ||
// The response handler | ||
function responseHandler(res) { | ||
// We might have a HAR, so let's try to replay | ||
// all the entries and return an array with the | ||
// responses in sequential order | ||
if (typeof target === 'object') { | ||
var data = [] | ||
harplayer.replayAll(target, function(err, res, body){ | ||
if (err) throw err | ||
data.push(buildResponse(res.statusCode)) | ||
if (data.length === target.log.entries.length) cb(data) | ||
}) | ||
} else if (typeof target === 'string') { | ||
// This is the response status code | ||
var code = res.status | ||
// Create our request object with the url and | ||
// a long timoeout, not following redirects then | ||
// put the request into our response handler | ||
unirest | ||
.get(target) | ||
.timeout(30000) | ||
.followRedirect(false) | ||
.end(function responseHandler(res) { | ||
var data = buildResponse(res.status) | ||
cb(data) | ||
}) | ||
// Create the ouput object | ||
var output = {} | ||
if (code && typeof code === 'number') { | ||
output["statusCode"] = code | ||
output["statusType"] = statusType(code) | ||
output["statusDescription"] = statusDescription(code) | ||
output["online"] = true | ||
} else { | ||
output["online"] = false | ||
} | ||
// Send the callback with the output | ||
cb(output) | ||
} else { | ||
throw new Error("Missing target URL") | ||
} | ||
// Create our request object with the url and | ||
// a long timoeout, not following redirects then | ||
// put the request into our response handler | ||
unirest | ||
.get(url) | ||
.timeout(30000) | ||
.followRedirect(false) | ||
.end(responseHandler) | ||
} | ||
@@ -51,3 +50,3 @@ | ||
} else { | ||
statusType = "Non-standardized Code" | ||
statusType = "Non-standard Code" | ||
} | ||
@@ -61,1 +60,15 @@ return statusType | ||
} | ||
// Helper function to format the response data | ||
function buildResponse(code) { | ||
var output = {} | ||
if (code && typeof code === 'number') { | ||
output["statusCode"] = code | ||
output["statusType"] = statusType(code) | ||
output["statusDescription"] = statusDescription(code) | ||
output["online"] = true | ||
} else { | ||
output["online"] = false | ||
} | ||
return output | ||
} |
{ | ||
"name": "apistatus", | ||
"version": "0.2.1", | ||
"version": "0.2.2", | ||
"description": "Returns the status of an HTTP request.", | ||
"main": "lib/apistatus.js", | ||
"scripts": { | ||
"test": "mocha --timeout 30000" | ||
"test": "mocha --timeout 30000 tests/" | ||
}, | ||
@@ -12,2 +12,3 @@ "author": "Mashape", | ||
"dependencies": { | ||
"harplayer": "^0.2.0", | ||
"unirest": "^0.4.0" | ||
@@ -14,0 +15,0 @@ }, |
# API Status [](https://travis-ci.org/Mashape/apistatus/)  | ||
API status is a simple tool that checks if an API is online. | ||
API status is a simple tool to send a request to an API and return response information. | ||
[](http://labs.mashape.com/apistatus) [](http://labs.mashape.com/apistatus) [](http://labs.mashape.com/apistatus) [](http://labs.mashape.com/apistatus) [](http://labs.mashape.com/apistatus) | ||
### Install | ||
@@ -8,0 +6,0 @@ |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
15519
42.64%11
10%447
71.92%2
100%45
-4.26%1
Infinity%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed