These are the general notes about the REST API protocol used by BaasBox and its JSON format.
If not specified otherwise, all requests need some custom HTTP headers.
These are BaasBox Authentications headers, since the 0.5.7 version supports two authentication methods: HTTP Basic Authentication, or via a Session Token.
It needs to provide the user’s credentials via the basic access authentication method. Username and password must be combined into a string “username:password” and then encoded using BASE64. The header must be in the form: Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ== . If the authentication fails, the server replies with BAD REQUEST http error (code 400) X-BAASBOX-APPCODE: This is the application code, by default this is: 1234567890
To use this authentication method, the client has to call the /users/login API. The Server will provide a token to use in the subsequent calls. All tokens will be invalidated if the server is stopped. To pass the session token to the server, use the following header:
X-BB-SESSION: 0000-1111-2222-3333
Every response generated by BaasBox as a result of a REST call is a JSON object with the following structure:
{
"result": "ok|ko",
"http_code": (200|201|204),
"data": {
...the data themselves...
}
}
In case of error, the data returned are more detailed and are useful to understand why the request was rejected. In this case, the JSON format is:
{
"result": "error",
"bb_code": xxx,
"message": "...a message explaining the problem in plain English...",
"resource": "...the REST API called....",
"method": "...the HTTP method used...",
"request_header": { .... the headers received by the server ...},
"API_version": "...the BaasBox API version..."
}
For bb_code see below.
These are custom error codes specific to BaasBox
Some APIs allow to specify query criteria. Accepted parameters are:
Example of valid calls: /document/mycoolestcollection/count?where=color%3D’yellow’ /document/mycoolestcollection/count?where=color%3D%3F¶ms%3dyellow /document/documents/count?where=color%3D%3F%20or%20color%3D%3F¶ms=yellow¶ms=cyan