User:YuviPanda/Dynamic http routing/API
A simple daemon that exposes an HTTP API to help configure Dynamic HTTP Routes.
Storage
It'll use a database (mysql or sqlite?) for its official source of 'truth'. Redis is kept in sync with the database, and nginx/lua will read directly from Redis.
Authentication
There'll be minimal auth support in the initial version. An 'admin token' needs to be sent by the client, via a HTTP Header (name tbd). The 'token' is just a shared secret that's shared out of band between the client and server.
Multi-tenancy is assumed (via {tenant_id}), but scoped tokens will not currently be supported.
API
Simple, versioned HTTP API.
Versioning is done by modifying the URL. Every URL specified needs to be prefixed with a /v<Number>, where Number is the version number, for it to work.
v1
Create new Mapping
Send a PUT request with a payload containing the mapping to be created.
PUT /v1/{tenant_id}/mapping
{"domain": "something.wmflabs.org", "backends": [ "http://instance-01:3000", "http://instance-02:4000" ] }
Response would be an appropriate HTTP response code, with JSON error messages if there are errors.
Delete a mapping
Send a DELETE request to the appropriate endpoint.
DELETE /v1/{tenant_id}/mapping/something.wmflabs.org
Response would be an appropriate HTTP response code, with JSON error messages if there are errors.
Get contents of a mapping
Send a GET request to the appropriate endpoint.
GET /v1/{tenant_id}/mapping/something.wmflabs.org
Response would be a JSON file with representations of the mapping specified, or a 404 if it wasn't found
List all mappings
GET /v1/{tenant_id}/mapping
Response would be the list of all mappings, 50 domains at a time, sorted by insert order. You can paginate via the offset and limit query parameters.
Update a mapping
Send a POST request with a payload with full JSON of the mapping.
PUT /v1/{tenant_id}/mapping/something.wmflabs.org
{"domain": "something.wmflabs.org", "backends": [ "http://instance-01:3000", "http://instance-02:4000" ] }
Response would be an appropriate HTTP response code, with JSON error messages if there are errors.
So the way to 'update' a mapping is to first do a GET, modify the JSON, and then do a POST. You can also rename them this way.