Create a Data Source

A data source is the first step to getting your data into your cache. With BadgerCache, you have two options for data sources: REST and GraphQL.

Setup an API connection. If the connection URL includes a parameter (such as a product ID), you can either hard code it here or use a data source variable. A data source variable allows you to fill in the parameter based on the particular cache key. Later, we'll talk about how to set the value of the data source variable when setting up the cache key. If you wish to use variables, follow the handlebar syntax: {{PRODUCT_ID}} - as an example. The data source values need to be setup before creating the cache key for them to be available. BadgerCache's IP addresses need to be whitelisted if the data source is behind a firewall.

Connection Details

Provide authentication headers. Follow best practices for limiting the access scope of the API token if applicable.

Set Headers

For GraphQL data sources:

Paste the GraphQL query. If it's a GraphQL connection, paste a properly formed query into the box. Pro tip is to use Apollo Studio to get the query.

GraphQL Query

Provide GraphQL variables. Also for GraphQL, provide any variables that need to be passed along the request. Select the data type to ensure it's honored when making the request. You can also use data source variables in the value field. More later on data source variables.

Set GraphQL Variables

For all connection types:

Test the connection result. Note, you'll need to temporarily remove data source variables and replace them with values to test. The connection should also be IP white listed if appliable. A good connection result will return a JSON object or string.

Test Connection Result

Transform the payload. If you'd like to cache a modified version of the object returned from the data source, you can write some simple JavaScript that will run during each job. Copy and paste a test JSON object from the data source response to test this functionality. Note: any dangerous If you don't want to include a transform function, and want to take the cached object from the data source as-is, just uncheck the box.

Transform Payload

If everything has been tested, at this point you should be able to save your new data source. Next you will setup a cache key to use it.