Product
Socket Now Supports uv.lock Files
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Bluecat
is a library that helps to easily create HTTP requests and maintain session information underlayer.
It could be integrated with any Node.js test framework and assertion library to create a clear and straighforward Web services API testing framework
.
Bluecat
automatically creates all the methods for youbluecat
command line interface comes with a nice configuration utility that helps you to create your test framework in less than a minute.$ npm install bluecat
POST /checkout/contract
GET /checkout/contract
{
"api": {
"checkout": {
"contract": {
"schema": "http",
"method": ["GET", "POST"]
}
}
}
}
var expect = require('chai').expect;
var Bluecat = require('bluecat');
var Service = new Bluecat.ServiceSync(Bluecat.Api('api'), 'sample-host.com');
// All requests need to be put as callback function in Service.run(), so they will run synchronously
Service.run(function() {
// send POST http://sample-host.com/checkout/contract
// with body: {"cartid": "test-cart-id"}
var r = Service.checkout.contract.POST({
body: {
cartid: 'test-cart-id'
}
});
// verify response
expect(r.data.statusCode).to.equal(200);
expect(r.data.body).to.have.ownProperty('id');
// send GET http://sample-host.com/checkout/contract
// cookies are automatically maintained if there is any
r = Service.checkout.contract.GET();
// verify response
expect(r.data.statusCode).to.equal(200);
expect(r.data.body.cartId).to.eql('test-cart-id');
})
PUT /search/fitness/result?start=0&limit=50&error=true
{
"api": {
"search": {
"fitness": {
"result": {
"schema": "https",
"method": ["PUT"]
}
}
}
}
}
var expect = require('chai').expect;
var Bluecat = require('bluecat');
var Service = new Bluecat.ServiceSync(Bluecat.Api('api'), 'sample-host.com');
// All requests need to be put as callback function in Service.run(), so they will run synchronously
Service.run(function() {
// send PUT http://sample-host.com/search/fitness/result?start=0&limit=50&error=true
// with body: {"term": "testTerm"}
// and header: {"User-agent": "automation"}
var r = Service.search.fitness.result.PUT({
body: {
term: 'testTerm'
},
query: {
start: 0,
limit: 50,
error: true
},
headers: {
'User-agent': 'automation'
}
});
// verify response
expect(r.data.statusCode).to.equal(200);
})
GET /cart/v1/add-item/item
{
"api": {
"cart": {
"v1": {
"add-item": {
"item": {
"schema": "http",
"method": ["GET"]
}
}
}
}
}
}
var expect = require('chai').expect;
var Bluecat = require('bluecat');
var Service = new Bluecat.ServiceSync(Bluecat.Api('api'), 'sample-host.com');
// All requests need to be put as callback function in Service.run(), so they will run synchronously
Service.run(function() {
// send GET http://sample-host.com/cart/v1/add-item/item
// we cannot use 'r = Service.cart.v1.add-item.item.GET()' because 'add-item' cannot be used
// as dot notation property accessor, we need to use bracket notation in such case
r = Service.cart.v1['add-item'].item.GET();
// verify response
expect(r.data.statusCode).to.equal(200);
})
GET /checkout/${uuid}/contract
{
"api": {
"checkout": {
"${uuid}": {
"contract": {
"schema": "http",
"method": ["GET"]
}
}
}
}
}
var expect = require('chai').expect;
var Bluecat = require('bluecat');
var Service = new Bluecat.ServiceSync(Bluecat.Api('api'), 'sample-host.com');
// All requests need to be put as callback function in Service.run(), so they will run synchronously
Service.run(function() {
// send GET http://sample-host.com/checkout/5e586387-6d5a-4874-8a98-5836bdc45c7b/contract
var r = Service.checkout['${uuid}'].contract.GET({
params: {
uuid: '5e586387-6d5a-4874-8a98-5836bdc45c7b'
}
});
// verify response
expect(r.data.statusCode).to.equal(200);
})
Bluecat.ServiceSync(api, host, options)
Create a new bluecat service object, with desired options.
var Bluecat = require('bluecat');
var Api = Bluecat.Api('mobileapi');
var Service = new Bluecat.ServiceSync(Api, 'api.mobile.walmart.com', {
gzip: true
});
rawRequest(options)
Sometimes we just want to send a request to some host, which is different than the API host we gave to the bluecat service object. You can use rawRequest(options)
to send it.
var Bluecat = require('bluecat');
var Api = Bluecat.Api('mobileapi');
var Service = new Bluecat.ServiceSync(Api, 'api.mobile.walmart.com');
var r = Service.rawRequest({
method: 'GET',
json: true,
uri: 'https://thirdparty-host/creditcard/encryption.js',
headers: {'accept-encoding': 'gzip'},
});
expect(r.err).to.equal(null);
expect(r.data.statusCode).to.equal(200);
setProxy(proxy)
Set proxy address, all the requests will be sent via a connection to the proxy server.
var Bluecat = require('bluecat');
var Api = Bluecat.Api('mobileapi');
var Service = new Bluecat.ServiceSync(Api, 'api.mobile.walmart.com');
Service.setProxy('http://127.0.0.1:8888')
resetCookie()
Clean up cookie jar, so the next request won't set any cookies in the header.
var Bluecat = require('bluecat');
var Api = Bluecat.Api('mobileapi');
var Service = new Bluecat.ServiceSync(Api, 'api.mobile.walmart.com');
Service.v1.products.search.GET();
Service.resetCookie();
Service.v1.cart.POST({
body: {
location: '94066'
}
})
setHeaders(headers)
Set headers that will be sent in all the requests.
var Bluecat = require('bluecat');
var Api = Bluecat.Api('mobileapi');
var Service = new Bluecat.ServiceSync(Api, 'api.mobile.walmart.com');
Service.setHeaders({'User-Agent': 'Automation'});
setSessionRules(rules)
Set extra session rules other than cookie. Some RESTful APIs defines their own session rules, you can set such rule to the bluecat service object, so you don't have to deal with it before sending every single HTTP request.
var Bluecat = require('bluecat');
var Api = Bluecat.Api('mobileapi');
var Service = new Bluecat.ServiceSync(Api, 'api.mobile.walmart.com');
// The following sessions rules start with value 'start-auth-token-value' in the request header AUTH_TOKEN,
// then grab new value from response header REFRESH_AUTH_TOKEN
// and put it in the next request header AUTH_TOKEN
Service.setSessionRules({
requestHeader: 'AUTH_TOKEN',
responseHeader: 'REFRESH_AUTH_TOKEN',
startSessionHeader: 'start-auth-token-value'
});
Bluecat comes with bluecat
command line interface that helps you to create a basic Web services API test framework.
$ npm install bluecat
$ ./node_modules/.bin/bluecat config
Follow the instructions and it will create a scaffold of basic web services API test framework for you.
Launch the node process like BLUECAT_DEBUG_FILE=/path/to/bluecat.log node script.js
to keep a log file of all the requests/responses information.
Launch the node process like BLUECAT_DEBUG_CONSOLE=true node script.js
to see all the requests/responses information from your console (stdout).
Licensed under the MIT
FAQs
Library for building RESTful API HTTP requests, best for generic RESTful API Test Framework
The npm package bluecat receives a total of 10 weekly downloads. As such, bluecat popularity was classified as not popular.
We found that bluecat demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.
Security News
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.