Skip to content

Commit dd0cc92

Browse files
authored
Start a 'conventions' section in the Appendices (#3350)
I wanted a section for "here's what new APIs ought to do", which isn't really very useful for consumers of the existing APIs.
1 parent 8b2c126 commit dd0cc92

File tree

3 files changed

+47
-24
lines changed

3 files changed

+47
-24
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add an 'API conventions' section to the Appendices.

content/appendices.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,3 +1039,22 @@ The event signing algorithm should emit the following signed event:
10391039
}
10401040
}
10411041
```
1042+
1043+
## Conventions for Matrix APIs
1044+
1045+
This section is intended primarily to guide API designers when adding to Matrix,
1046+
setting guidelines to follow for how those APIs should work. This is important to
1047+
maintain consistency with the Matrix protocol, and thus improve developer
1048+
experience.
1049+
1050+
### HTTP endpoint and JSON property naming
1051+
1052+
The names of the API endpoints for the HTTP transport follow a convention of
1053+
using underscores to separate words (for example `/delete_devices`).
1054+
1055+
The key names in JSON objects passed over the API also follow this convention.
1056+
1057+
{{% boxes/note %}}
1058+
There are a few historical exceptions to this rule, such as `/createRoom`.
1059+
These inconsistencies may be addressed in future versions of this specification.
1060+
{{% /boxes/note %}}

content/client-server-api/_index.md

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ weight: 10
44
type: docs
55
---
66

7-
The client-server API provides a simple lightweight API to let clients
7+
The client-server API allows clients to
88
send messages, control rooms and synchronise conversation history. It is
99
designed to support both lightweight clients which store no state and
1010
lazy-load data from the server as required - as well as heavyweight
@@ -20,20 +20,15 @@ supported as optional extensions - e.g. a packed binary encoding over
2020
stream-cipher encrypted TCP socket for low-bandwidth/low-roundtrip
2121
mobile usage. For the default HTTP transport, all API calls use a
2222
Content-Type of `application/json`. In addition, all strings MUST be
23-
encoded as UTF-8. Clients are authenticated using opaque `access_token`
24-
strings (see [Client Authentication](#client-authentication) for
25-
details), passed as a query string parameter on all requests.
23+
encoded as UTF-8.
2624

27-
The names of the API endpoints for the HTTP transport follow a
28-
convention of using underscores to separate words (for example
29-
`/delete_devices`). The key names in JSON objects passed over the API
30-
also follow this convention.
25+
Clients are authenticated using opaque `access_token` strings (see [Client
26+
Authentication](#client-authentication) for details).
3127

32-
{{% boxes/note %}}
33-
There are a few historical exceptions to this rule, such as
34-
`/createRoom`. A future version of this specification will address the
35-
inconsistency.
36-
{{% /boxes/note %}}
28+
See also [Conventions for Matrix APIs](/appendices#conventions-for-matrix-apis)
29+
in the Appendices for conventions which all Matrix APIs are expected to follow.
30+
31+
### Standard error response
3732

3833
Any errors which occur at the Matrix API level MUST return a "standard
3934
error response". This is a JSON object which looks like:
@@ -46,15 +41,17 @@ error response". This is a JSON object which looks like:
4641
```
4742

4843
The `error` string will be a human-readable error message, usually a
49-
sentence explaining what went wrong. The `errcode` string will be a
50-
unique string which can be used to handle an error message e.g.
51-
`M_FORBIDDEN`. These error codes should have their namespace first in
52-
ALL CAPS, followed by a single \_ to ease separating the namespace from
53-
the error code. For example, if there was a custom namespace
54-
`com.mydomain.here`, and a `FORBIDDEN` code, the error code should look
55-
like `COM.MYDOMAIN.HERE_FORBIDDEN`. There may be additional keys
56-
depending on the error, but the keys `error` and `errcode` MUST always
57-
be present.
44+
sentence explaining what went wrong.
45+
46+
The `errcode` string will be a unique string which can be used to handle an
47+
error message e.g. `M_FORBIDDEN`. Error codes should have their namespace
48+
first in ALL CAPS, followed by a single `_`. For example, if there was a custom
49+
namespace `com.mydomain.here`, and a `FORBIDDEN` code, the error code should
50+
look like `COM.MYDOMAIN.HERE_FORBIDDEN`. Error codes defined by this
51+
specification should start `M_`.
52+
53+
Some `errcode`s define additional keys which should be present in the error
54+
response object, but the keys `error` and `errcode` MUST always be present.
5855

5956
Errors are generally best expressed by their error code rather than the
6057
HTTP status code returned. When encountering the error code `M_UNKNOWN`,
@@ -66,7 +63,9 @@ found. However, if the client were to receive an error code of
6663
`M_UNKNOWN` with a 400 Bad Request, the client should assume that the
6764
request being made was invalid.
6865

69-
The common error codes are:
66+
#### Common error codes
67+
68+
These error codes can be returned by any API endpoint:
7069

7170
`M_FORBIDDEN`
7271
Forbidden access, e.g. joining a room without permission, failed login.
@@ -98,7 +97,11 @@ then try again.
9897
`M_UNKNOWN`
9998
An unknown error has occurred.
10099

101-
Other error codes the client might encounter are:
100+
#### Other error codes
101+
102+
The following error codes are specific to certain endpoints.
103+
104+
<!-- TODO: move them to the endpoints that return them -->.
102105

103106
`M_UNRECOGNIZED`
104107
The server did not understand the request.

0 commit comments

Comments
 (0)