You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/php/api/rpc_api.md
+24-25Lines changed: 24 additions & 25 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,25 +9,25 @@ You are more than welcome to share any feedback, including but not limited to su
9
9
10
10
The implementation of the RPC API is built in a way that it could support a token based authentication in the future but this is entirely out of scope for the current iteration.
11
11
12
-
# Predictable API
12
+
##Predictable API
13
13
14
-
## Idempotency Whenever Reasonably Possible
14
+
###Idempotency Whenever Reasonably Possible
15
15
16
16
Some endpoints will perform a specific action, such as following a user or reacting to a message. These endpoints SHOULD be idempotent whenever possible, treating the request to be the “should” state.
17
17
18
18
For example, following a user for the first time should produce the same response as attempting to follow them again while still following. Reacting to a message that has already been reacted to using a difference reaction should implicitly revoke the previous reaction. If the user has already reacted using the same reaction then no change should be made. However, in both cases the response should be indistinguishable from reacting to a message for the first time.
19
19
20
-
## HTTP Verbs
20
+
###HTTP Verbs
21
21
22
22
We will only support three basic verbs: `GET`, `POST` and `DELETE`.
23
23
24
24
Some implementations also make use of `PATCH` and `PUT`, but this would make it much more complex and adds little benefit plus its quite verbose since the verb implies the semantics of the endpoint. The same can be achieved by using distinct endpoints and using `POST` instead. Plus historically the support for `PATCH` and `PUT` was rather poor.
25
25
26
-
## Response Format
26
+
###Response Format
27
27
28
28
The PSR messaging interface allows for a host of useful response types, such as `204 No Content`, returning a plain “HTML” response or any format that is suitable. While this is more efficient, it also makes the API much more complicated and less predictable, requiring different response handling based on the endpoint being targeted.
@@ -39,7 +39,7 @@ The PSR messaging interface allows for a host of useful response types, such as
39
39
| 500 | Internal Server Error | The server failed to process the request. |
40
40
| 503 | Service Unavailable | The API is currently unavailable. |
41
41
42
-
## Error Format
42
+
###Error Format
43
43
44
44
Whenever a request is rejected with the error code 400, the response will match the following data structure:
45
45
@@ -63,25 +63,25 @@ A typical response could look like this:
63
63
}
64
64
```
65
65
66
-
### `type`
66
+
####`type`
67
67
68
68
The error type is used to tell apart issues caused by the request being made by the client or by unexpected errors taking place on the server side processing.
69
69
70
-
### `code`
70
+
####`code`
71
71
72
72
The error code is all lowercase and using snake case to describe the type of error, for example, `missing_api_key`.
73
73
74
-
### `message`
74
+
####`message`
75
75
76
76
The message can be empty but when present contains a non-localized string explaining the cause of the error with the intention of assisting a developer to resolve the issue.
77
77
78
78
You MUST NOT present this message to the end user.
79
79
80
-
### `param`
80
+
####`param`
81
81
82
82
Validation errors may refer to a specific parameter that has caused the request to be rejected. A common use case is to point to a specific input field, allowing for contextual error message presented to the user.
83
83
84
-
## Examples
84
+
###Examples
85
85
86
86
The endpoints below may or may not exist at any point and are only used for illustration purposes.
87
87
@@ -97,9 +97,9 @@ The endpoints below may or may not exist at any point and are only used for illu
97
97
| - | - | - |
98
98
|`DELETE`|`/forum/threads/{id:\d+}`| Deletes a thread. |
99
99
100
-
# Implementation of an Endpoint
100
+
##Implementation of an Endpoint
101
101
102
-
## Namespaces for Endpoints
102
+
###Namespaces for Endpoints
103
103
104
104
Endpoints are defined using a strict rule set:
105
105
@@ -109,19 +109,23 @@ Endpoints are defined using a strict rule set:
109
109
- Parameters MAY appear starting with the third path segment and are defined with a leading colon.
110
110
- The name of a parameter MUST be unique within one endpoint.
111
111
112
-
## Convention for File Name and Location
112
+
###Convention for File Name and Location
113
113
114
114
It is strongly recommended to place the files in `lib/system/endpoint/controller/<namespace>/<objects>/<nameOfTheAction>.class.php`.
115
115
The file name should reflect the action itself, following the pattern `<Verb><Object>`, for example, `DeleteFile` or `CreatePost`.
116
116
117
-
## Registering the Route of an Endpoint
117
+
###Registering the Route of an Endpoint
118
118
119
119
Every endpoint needs to implement `wcf\system\endpoint\IController` which defines the `__invoke()` method that will receive the `ServerRequestInterface` and an array containing any defined route parameters.
120
120
121
121
Any endpoint can only ever serve a single verb, registered through the use of the `wcf\system\endpoint\GetRequest`, `wcf\system\endpoint\PostRequest` or `wcf\system\endpoint\DeleteRequest` class attribute.
122
122
The attribute expects a single parameter to define the endpoint’s route.
123
123
124
-
## Registering of an Endpoint
124
+
#### Placeholders
125
+
126
+
The route implementation uses [FastRoute](https://github.com/nikic/FastRoute) which supports named placeholders through the `{name}` syntax. Optionally, a validation pattern can be specified to further narrow down the valid value of the placeholder: `{id:\d+}`
127
+
128
+
### Registering of an Endpoint
125
129
126
130
Custom endpoints can be registered via the `ControllerCollecting` event in the [bootstrap script](../../package/bootstrap-scripts.md) of a package.
127
131
@@ -139,30 +143,25 @@ return static function (): void {
139
143
};
140
144
```
141
145
142
-
143
-
### Placeholders
144
-
145
-
The route implementation uses [FastRoute](https://github.com/nikic/FastRoute) which supports named placeholders through the `{name}` syntax. Optionally, a validation pattern can be specified to further narrow down the valid value of the placeholder: `{id:\d+}`
146
-
147
-
## Available Helper Methods
146
+
### Available Helper Methods
148
147
149
148
The `wcf\http\Helper` class offers a few helpful methods that simplify the validation and processing of request parameters.
0 commit comments