@@ -4,7 +4,7 @@ weight: 10
4
4
type : docs
5
5
---
6
6
7
- The client-server API provides a simple lightweight API to let clients
7
+ The client-server API allows clients to
8
8
send messages, control rooms and synchronise conversation history. It is
9
9
designed to support both lightweight clients which store no state and
10
10
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
20
20
stream-cipher encrypted TCP socket for low-bandwidth/low-roundtrip
21
21
mobile usage. For the default HTTP transport, all API calls use a
22
22
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.
26
24
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).
31
27
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
37
32
38
33
Any errors which occur at the Matrix API level MUST return a "standard
39
34
error response". This is a JSON object which looks like:
@@ -46,15 +41,17 @@ error response". This is a JSON object which looks like:
46
41
```
47
42
48
43
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.
58
55
59
56
Errors are generally best expressed by their error code rather than the
60
57
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
66
63
` M_UNKNOWN ` with a 400 Bad Request, the client should assume that the
67
64
request being made was invalid.
68
65
69
- The common error codes are:
66
+ #### Common error codes
67
+
68
+ These error codes can be returned by any API endpoint:
70
69
71
70
` M_FORBIDDEN `
72
71
Forbidden access, e.g. joining a room without permission, failed login.
@@ -98,7 +97,11 @@ then try again.
98
97
` M_UNKNOWN `
99
98
An unknown error has occurred.
100
99
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 --> .
102
105
103
106
` M_UNRECOGNIZED `
104
107
The server did not understand the request.
0 commit comments