Controlling API output with intercepts

For a given API key and collection, restdb.io lets you control the API output. This is done by specifying a query and/or hints for the given API-key/collection-combo. The query from the intercept will be AND'ed together with the incoming query and the hints will be merged.

This feature can be very useful in cases where you only want to expose certain fields or just a subset of your data with a specific API-key.

In the Settings tab (while in development mode) you can enter a JSON configuration setting to set up the intercept.

{
  "restdb": {
   "intercepts": {
      "5ba5231abd79780aab0a7654": {
        "participants":{
           "query": "{\"companyname\":\"Acme Inc\"}",
           "hints": "{\"$fields\":{\"name\":1,\"paid\":1}}"
        }
      }
    }
  }
}

Because both query and hints accepts only a string (not JSON), remember to escape the " like this \".

This setup, will ensure that queries using the api key 5ba5231abd79780aab0a7654 and with collection name participants, will be filtered to only display the records where companyname is "Acme Inc". Only the fields name and paid will be returned:

[
  {"name": "Peter Adamson", "paid":false},
  {"name": "Jane Amhurst", "paid":true},
...
]