StereoSwitch exposes a json/HTTP API for discovering and connecting inputs to outputs.
The use-case is a web-controllable analogue audio switch: one out of a number of defined inputs go to one of a number of defined outputs. This requires hardware which at the moment only exists on the back of a napkin.
Run it with:
$ sbt run
The methods and JSON object formats are described below. Endpoints (inputs and outputs) are identified by a numerical id. This is the order in which they are returned by sending a GET to /connections.
Two types of objects are used by the StereoSwitch API:
Connections are pairs of source id and a destination id:
{
"connection": {
"source": Int,
"destination": Int
}
}
These are either inputs or outputs:
{
"input": {
"name": String
}
}
The following resources and methods are defined:
- GET: responds with list of endpoints as a json object of "sources":sources and "destinations":destinations where sources and destinations are json arrays of input objecst and output objects, respectively.
- GET: responds with list of inputs as a json array of input objects.
- GET: responds with the single input object with a given id, or HTTP status code 404 if no object with this id exists.
- GET: responds with a list of destinations as a json array of output objects.
- GET: responds with the single input object with the given id, or HTTP status code 404 if no object with this id exists.
-
GET: responds with a single connection object describing the currently connected input and output.
-
PUT: accepts a connection object and attempts to make the connection described. If this fails (because either endpoint doesn't exist), HTTP status code 422 is returned.