Skip to content

Latest commit

 

History

History
129 lines (98 loc) · 2.97 KB

cherryPickingKeygen.md

File metadata and controls

129 lines (98 loc) · 2.97 KB

Cherry Picking Keygen

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.

Usage

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']
    }]
});

Cherry picking options

properties

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']
    }]
});

url

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']
    }]
});

query

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']
    }]
});

headers

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']
    }]
});

fixed

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' }]
    }]
});

body

When using the request body an xpath or json picker needs to be selected.

xpath

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()'
            ]
        }
    }]
});

json

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']
        }
    }]
});