Skip to content

Commit 7e0fe15

Browse files
committed
Fix headlines
1 parent 7a55589 commit 7e0fe15

File tree

1 file changed

+24
-25
lines changed

1 file changed

+24
-25
lines changed

docs/php/api/rpc_api.md

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,25 @@ You are more than welcome to share any feedback, including but not limited to su
99

1010
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.
1111

12-
# Predictable API
12+
## Predictable API
1313

14-
## Idempotency Whenever Reasonably Possible
14+
### Idempotency Whenever Reasonably Possible
1515

1616
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.
1717

1818
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.
1919

20-
## HTTP Verbs
20+
### HTTP Verbs
2121

2222
We will only support three basic verbs: `GET`, `POST` and `DELETE`.
2323

2424
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.
2525

26-
## Response Format
26+
### Response Format
2727

2828
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.
2929

30-
## HTTP Status Codes
30+
### HTTP Status Codes
3131

3232
| Code | Name | Meaning |
3333
| ---- | --------------------- | --------------------------------------------------------- |
@@ -39,7 +39,7 @@ The PSR messaging interface allows for a host of useful response types, such as
3939
| 500 | Internal Server Error | The server failed to process the request. |
4040
| 503 | Service Unavailable | The API is currently unavailable. |
4141

42-
## Error Format
42+
### Error Format
4343

4444
Whenever a request is rejected with the error code 400, the response will match the following data structure:
4545

@@ -63,25 +63,25 @@ A typical response could look like this:
6363
}
6464
```
6565

66-
### `type`
66+
#### `type`
6767

6868
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.
6969

70-
### `code`
70+
#### `code`
7171

7272
The error code is all lowercase and using snake case to describe the type of error, for example, `missing_api_key`.
7373

74-
### `message`
74+
#### `message`
7575

7676
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.
7777

7878
You MUST NOT present this message to the end user.
7979

80-
### `param`
80+
#### `param`
8181

8282
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.
8383

84-
## Examples
84+
### Examples
8585

8686
The endpoints below may or may not exist at any point and are only used for illustration purposes.
8787

@@ -97,9 +97,9 @@ The endpoints below may or may not exist at any point and are only used for illu
9797
| - | - | - |
9898
| `DELETE` | `/forum/threads/{id:\d+}` | Deletes a thread. |
9999

100-
# Implementation of an Endpoint
100+
## Implementation of an Endpoint
101101

102-
## Namespaces for Endpoints
102+
### Namespaces for Endpoints
103103

104104
Endpoints are defined using a strict rule set:
105105

@@ -109,19 +109,23 @@ Endpoints are defined using a strict rule set:
109109
- Parameters MAY appear starting with the third path segment and are defined with a leading colon.
110110
- The name of a parameter MUST be unique within one endpoint.
111111

112-
## Convention for File Name and Location
112+
### Convention for File Name and Location
113113

114114
It is strongly recommended to place the files in `lib/system/endpoint/controller/<namespace>/<objects>/<nameOfTheAction>.class.php`.
115115
The file name should reflect the action itself, following the pattern `<Verb><Object>`, for example, `DeleteFile` or `CreatePost`.
116116

117-
## Registering the Route of an Endpoint
117+
### Registering the Route of an Endpoint
118118

119119
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.
120120

121121
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.
122122
The attribute expects a single parameter to define the endpoint’s route.
123123

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
125129

126130
Custom endpoints can be registered via the `ControllerCollecting` event in the [bootstrap script](../../package/bootstrap-scripts.md) of a package.
127131

@@ -139,30 +143,25 @@ return static function (): void {
139143
};
140144
```
141145

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
148147

149148
The `wcf\http\Helper` class offers a few helpful methods that simplify the validation and processing of request parameters.
150149

151-
### `mapApiParameters(ServerRequestInterface $request, string $className)`
150+
#### `mapApiParameters(ServerRequestInterface $request, string $className)`
152151

153152
Takes the `$request` from the `__invoke()` call and maps the parameters against the provided class name.
154153
By convention it is recommended to use an internal class that is defined at the end of the class file and uses a `Parameters` suffix.
155154

156155
For `GET` and `DELETE` requests the query string is used as the source.
157156
For `POST` requests the request body is mapped to the parameters.
158157

159-
### `fetchObjectFromRequestParameter(int|string $objectID, string $className)`
158+
#### `fetchObjectFromRequestParameter(int|string $objectID, string $className)`
160159

161160
Expects `$className` to be derived from `wcf\data\DatabaseObject` and attempts to fetch it using the `$objectID` parameter.
162161
Afterwards the object is tested to have a non-falsy object id, otherwise a `UserInputException` is raised.
163162

164163
Returns the fetched object on success.
165164

166-
# Interacting with the PHP RPC API in TypeScript
165+
## Interacting with the PHP RPC API in TypeScript
167166

168167
You can find an introduction to the [TypeScript API for the RPC API](../../javascript/components_rpc_api.md) in the documentation.

0 commit comments

Comments
 (0)