Configuration
Configuration in Bigsby follows a cascading pattern running from the top level, the default config, to the bottom level decorated config. The configs defined at each level are merged on top of the previous level.
Default Config
A Bigsby instance is bootstrapped with default configuration settings for important functionality:
request.enableTypeCoercion = true
response.enableInferContentType = true
Instance Config
When creating a Bigsby instance, it's possible to specify configuration for Bigsby itself, as well as options that will be inherited by every handler created by the instance.
const bigsby = new Bigsby({
api: {
response: {
headers: {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET",
},
},
},
});
At any point after creation, you can reset the settings of your Bigsby instance using the setConfig
method. This will result in all previous configurations being erased, and the inputs configurations being merged
directly on top of the default configs.
bigsby.setConfig({
api: {
response: {
headers: {
"Access-Control-Allow-Origin": "https://mydomain.com",
"Access-Control-Allow-Methods": "POST",
},
},
},
});
It's possible to merge a new set of configs onto the existing instance configs without resetting them using
the patchConfig
method.
bigsby.patchConfig({
api: {
response: {
headers: {
"Access-Control-Allow-Methods": "*",
},
},
},
});
Inline Config
Inline configuration can be set directly on a handler by providing a config object when creating the handler
using createApiHandler
. Configs set at this level will take precedence over those set at the instance level.
@Api()
class ArnyQuotesHandler implements ApiHandler {
public async invoke(): Promise<string> {
return getQuote();
}
}
export default bigsby.createApiHandler(ArnyQuotesHandler, {
lifecycle: {
onError: [sendAlert],
},
});
Decorated Config
Decorating your handler classes is another method of providing configuration. Similar to inline config
you can provide configs directly to your handler, but instead by adding them as an argument to the @Api
decorator.
@Api({
lifecycle: {
onError: [sendAlert],
},
})
class ArnyQuotesHandler implements ApiHandler {
public async invoke(): Promise<string> {
return getQuote();
}
}
export default bigsby.createApiHandler(ArnyQuotesHandler);
More specific settings like authentication, validation, and versioning use their specialised decorators to apply the configuration and are interpreted by Bigsby when creating the handler.
All decorated configs take precedence over those set at the inline or instance level.