Generate a request key from an incoming request.
The cherry picking keygen will pick all the 'cherries' that you define into an object and stringify it to create the request key.
The subject of the picking is a prepared forwarding message to the matching endpoint url. For example, an endpoint that would forward to google.com would get google.com
returned as host
property.
Note: If you change the request key generator config this may result in your existing caches no longer hitting.
It can be configured for all endpoints or per endpoint:
var $nocca = require('nocca');
var nocca = new $nocca({
keyGenerator: ['cherryPickingKeygen', {
properties: ['path', 'method'],
url: ['pathname'],
headers: ['accept', 'content-type', 'soapaction']
}]
});
An array of properties picked from the httpMessage
object. Can be:
var $nocca = require('nocca');
var nocca = new $nocca({
keyGenerator: ['cherryPickingKeygen', {
properties: ['method', 'host', 'protocol', 'port', 'path', 'headers', 'body']
}]
});
An array of properties picked from the request url path:
var $nocca = require('nocca');
var nocca = new $nocca({
keyGenerator: ['cherryPickingKeygen', {
url: ['search', 'query', 'pathname', 'path', 'href']
}]
});
An array of the query param names that should be extracted from the request.
var $nocca = require('nocca');
var nocca = new $nocca({
keyGenerator: ['cherryPickingKeygen', {
query: ['your', 'query', 'param']
}]
});
An array of the header names that should be extracted from the request.
var $nocca = require('nocca');
var nocca = new $nocca({
keyGenerator: ['cherryPickingKeygen', {
headers: ['accept', 'content-type']
}]
});
A fixed object to add to the key. May be anything stringify-able:
var $nocca = require('nocca');
var nocca = new $nocca({
keyGenerator: ['cherryPickingKeygen', {
fixed: ['customstring', { some: 'object' }]
}]
});
When using the request body an xpath
or json
picker needs to be selected.
Use xpath
queries on the request body:
var $nocca = require('nocca');
var nocca = new $nocca({
keyGenerator: ['cherryPickingKeygen', {
body: {
xpath: [
'//*[local-name()="CustomerIdentifier"]/text()',
'//*[local-name()="IdentifierType"]/text()',
'//*[local-name()="Body"]/*/*[local-name()="Password"]/text()'
]
}
}]
});
Retrieves properties from the message body JSON object. Formatted as dot-separated path:
var $nocca = require('nocca');
var nocca = new $nocca({
keyGenerator: ['cherryPickingKeygen', {
body: {
json: ['user.id']
}
}]
});