Config File

The config file has the main section for options, and a list of services to expose the desired APIs.

Currently the only available global option is autoreload, that when set to true will monitor changes on the config file to reload all services (currently, it does detect the actual change to only respawn the modified / added / deleted services).

So this is a perfect valid configuration to start with:

{
  "autoreload": true,
  "services": []
}

Service

For each service we must define the port and host to listen to, and specify any number of endpoints that we want to expose.

{
  "port": 9877,
  "host": "0.0.0.0",
  "endpoints": []
}

Endpoint

In the endpoint we define the route and optionally the method to be exposed. If no method, or empty string method is provided, the route will be matched against all methods.

For each endpoint, we can specify a list of behaviours to apply, and a way to provide the response and body content.

These are the fields available:

  • method: an uppercased http method: ‘GET’, ‘POST’, …
  • route: The server uses the Go’s standard lib router, so, to define a route you can follow the patterns documentation, with the slight difference that the method is specified in the method field.
  • behaviour: a list of behaviours to apply (see explanation below).
  • content: configuration about the content to serve with the request (headers and body are generated at this level).

Example:

{
  "method": "GET",
  "route": "/some_route/",
  "behaviour": [],
  "content": {
    "source": "directory",
    "config": {
      "path": "./example/data"
    }
  }
}

Route matching

Routing is based on GO’s standard library http router, however, in the configuration the host is determined at the service level, and the method is provided as a different property.

The route must always start with a /

  • "/index.html" matches the path “/index.html” for any host and method.
  • "/{$}" matches requests with path “/”: the
  • Parameters can be matched and captured with this notation: "/b/{bucket}/o/{objectname...}":
    matches paths whose first segment is "b" and whose third segment is "o". The name "bucket" denotes the second segment and “objectname” denotes the remainder of the path. Matching of several segments can only be done at the end of the path.

Behaviour

A Behaviour defines the result and how a content will be delivered.

Multiple behaviors can be provided, and will be applied in the order that appear in the configuration list.

Example:

{
"behaviour": [
  {
    "name": "slower",
    "config": {
      "max_bytes_per_second": 100,
      "flush_bytes": 2
    }
  },
  {
    "name": "status_distributor",
    "config": {
      "code_distribution": [
        {
          "key": 200,
          "val": 0.7
        },
        {
          "key": 500,
          "val": 0.3
        }
      ],
      "seed": 1
    }
  }
]
}

Check the behaviours documentation to know more.

Content

A single content provider can be given for each source, however, some content providers have the options to select among several nested content providers.

Example:

{
"content": {
  "source": "directory",
  "config": {
    "path": "./example/data"
  }
}

Check the content documentation to know more.