apigee-utils v4.1.0
apigee-utils
A set of utility functions to ease javascript development on the Apigee Edge api platform
Installation
npm i -S apigee-utilsyarn add apigee-utilsHow to use?
The utilities can be imported directly by using the modular build or all of them directly.
import getBody from 'apigee-utils/getBody';import {getBody} from 'apigee-utils';Reference
getBody
This will get the post body from the request
Returns any The body of the request
getQueryParam
This will get a queryParam from the passed url string
Parameters
queryParamKeystring The key for the queryParamdefaultValuestring? The default value to return when nothing is available
Returns string? The value of the queryParam
getQueryParams
This will get a set of queryParams from the passed url string
Parameters
possibleQueryParamsArray<string> An array containing possible queryparamssettingsany Object containing the settings for getting the queryparamssettings.defaultValuesThe value to return when no value is found. The keys of the default values should be identical to the queryparam keys.
Returns {} An object containing values for the passed in queryparams
setQueryParam
This will set a query parameter to the provided value
Parameters
keystring The key of the queryparam to setvalueany The value to set the queryparam to
Returns void
setQueryParams
This will convert an object with key value pairs to query parameters
Parameters
queryParams{} An object containing key value pairs to be used as query parameters
Returns void
validateValues
This will validate a set of query parameters and will set a error variable in the apigee with an errorpayload variable which can be send down to the client It is advised to set up a raise on error policy which will return the payload when the error variable == true
Parameters
values{} The keys the values to get are stored withsettingsany Object containing the settings for getting the variablessettings.validatorThe validator is an object containing functions which take a value and tests whether the value matches to required format returning true for a valid parameter and false for invalid. Or it can return a custom error message as a string. It is also possible to return mutliple error messages as an array of strings. The keys of the validator should be identical to the queryparam keys.settings.prefixThe prefix to use for the variables which will be used to set the potential error messages
Returns boolean A boolean indicating whether the query param were valid or not
createErrorObject
This will create the default error message
Parameters
keystring The key of the query parametervalueany The value of the query parametermessagestring The custom message to use
Returns {title: string, message: string, source: string} A default error object
setVariable
This will store a value in the Apigee flow
Parameters
keystring The key the value should be stored invalueany The value to storesettingsany Object containing the settings for setting the variablesettings.prefixA prefix which is used to store the value with
Returns void
setVariables
This will store a set of values in the Apigee flow
Parameters
variables{} An object containing key value pairs to storesettingsany Object containing the settings for setting the variablessettings.prefixA prefix which is used to store the value with
Returns void
validateBoolean
This will do a simple check if the passed string is a stringified boolean or not
Parameters
settingsany An object containing the options for validationsettings.nameThe name of the variable to checksettings.valueThe value of the variable to checksettings.requiredWhether it's required (allow undefined values or not)
Returns string A default error message or an empty string
validateEnum
This will do a simple check if the passed value is one of the valid values
Parameters
settingsany An object containing the options for validationsettings.nameThe name of the variable to checksettings.valueThe value of the variable to checksettings.requiredWhether it's required (allow undefined values or not)settings.validValuesThe possible values
Returns string A default error message or an empty string
validateMultipleEnum
This will do a simple check if the passed string of values contains one or more valid values
Parameters
settingsany An object containing the options for validationsettings.nameThe name of the variable to checksettings.valuesThe values of the variable to check (must be a string seperated by commas)settings.requiredWhether it's required (allow undefined values or not)settings.validValuesThe possible values
Returns string A default error message or an empty string
validateBounds
This will do a simple check if the passed string of values is a valid latitude and longitude map bounds
Parameters
settingsany An object containing the options for validationsettings.nameThe name of the variable to checksettings.valueThe bounds valuesettings.requiredWhether it's required (allow undefined values or not)
Returns any A default error message or an empty array
getProxyResponse
This will get the response from the proxy
Parameters
settingsany Object containing the settings for getting the response from the proxysettings.characterEncodingOptionally convert the response to UTF-8
Returns any The response from the targetted API
setResponse
This will set the response to the provided content
Parameters
contentany The response to set for the proxysettingsany Object containing the settings for setting the responsesettings.contentTypeAn optional contenttype header to set for the response
Returns void
getVariable
This will get a value from the Apigee flow
Parameters
keystring The key the value to get is stored withsettingsany Object containing the settings for getting the variablesettings.prefixA prefix which is used to store the value withsettings.defaultValueThe value to return when no value is foundsettings.parserThe parser is a function which takes a value and transforms it to return something else
Returns any The value parsed from the apigee flow
getVariables
This will get a set of values from the Apigee flow
Parameters
keysArray<string> The keys the values to get are stored withsettingsany Object containing the settings for getting the variablessettings.prefixA prefix which is used to store the value withsettings.defaultValuesThe value to return when no value is found. The keys of the default values should be identical to the variable keys.settings.parserThe parser is an object containing functions which take a value and transforms it to return something else. The keys of the parser should be identical to the variable keys.
Returns {} The values parsed from the apigee flow
logMessage
This will log a message to the syslog variable
Parameters
additionalLogvalues{}? Object containing additional key values to be logged
Returns void
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago