Comparing version 0.0.1 to 0.0.2
const http = require('http'); | ||
const assert = require('assert'); | ||
@@ -31,2 +32,48 @@ function request(url, headers, method, data){ | ||
class Suite{ | ||
constructor(response){ | ||
this.response = response; | ||
} | ||
status(s){ | ||
let status = this.response.status; | ||
switch(typeof s){ | ||
case 'number': assert.deepEqual(s, status); break; | ||
} | ||
return this; | ||
} | ||
json(cb){ | ||
let body = JSON.parse(this.response.body); | ||
assert(cb(body)); | ||
return this; | ||
} | ||
} | ||
class Endpoint{ | ||
constructor(method, url){ | ||
this.method = method; | ||
this.url = url; | ||
} | ||
async query(params, headersOrBody, body){ | ||
let oldURL = this.url; | ||
this.url += '?' + params; | ||
let r = await this.reach(headersOrBody, body); | ||
this.url = oldURL; | ||
return r; | ||
} | ||
async reach(headersOrBody, body){ | ||
body = body || headersOrBody; | ||
let r = await request(this.url, headersOrBody, this.method, body); | ||
return new Suite(r); | ||
} | ||
} | ||
module.exports = { | ||
@@ -64,3 +111,7 @@ get(url, headers){ | ||
request: request | ||
request: request, | ||
Endpoint: Endpoint | ||
}; | ||
module.exports.del = module.exports.delete; |
{ | ||
"name": "muhb", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "A simple set of functions for coding easy to read HTTP requests.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11934
166