New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

apistatus

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

apistatus - npm Package Compare versions

Comparing version

to
0.2.2

tests/har.json

69

lib/apistatus.js
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 [![Travis CI](https://img.shields.io/travis/Mashape/apistatus.svg)](https://travis-ci.org/Mashape/apistatus/) ![License](https://img.shields.io/npm/l/apistatus.svg)
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.
[![API Status](https://img.shields.io/badge/API-online-brightgreen.svg)](http://labs.mashape.com/apistatus) [![API Status](https://img.shields.io/badge/API-301%20redirect-yellowgreen.svg)](http://labs.mashape.com/apistatus) [![API Status](https://img.shields.io/badge/API-404%20client%20error-orange.svg)](http://labs.mashape.com/apistatus) [![API Status](https://img.shields.io/badge/API-501%20server%20error-red.svg)](http://labs.mashape.com/apistatus) [![API Status](https://img.shields.io/badge/API-offline-lightgray.svg)](http://labs.mashape.com/apistatus)
### Install

@@ -8,0 +6,0 @@