Skip to content

Commit 891e519

Browse files
committed
docs: improve API reference readability
1 parent 04d42e0 commit 891e519

3 files changed

Lines changed: 209 additions & 52 deletions

File tree

docs/03-api.md

Lines changed: 137 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,20 @@
44

55
This page documents the public API facade methods available to SDK authors and advanced SDK users.
66

7-
## `send(string $method, string $path, array $pathParams = [], array $query = [], array $headers = [], string|StreamInterface|null $body = null): Response`
7+
## Request Execution
8+
9+
### `send()`
10+
11+
```php
12+
send(
13+
string $method,
14+
string $path,
15+
array $pathParams = [],
16+
array $query = [],
17+
array $headers = [],
18+
string|StreamInterface|null $body = null,
19+
): Response
20+
```
821

922
Public low-level request helper.
1023

@@ -34,7 +47,13 @@ Path parameters are encoded and replaced in `{name}` placeholders.
3447
- Authentication, plugins, cache, and hooks.
3548
- Response decoding and error mapping.
3649

37-
## `config(array $values = [], array $defaults = []): Config`
50+
## SDK Setup
51+
52+
### `config()`
53+
54+
```php
55+
config(array $values = [], array $defaults = []): Config
56+
```
3857

3958
Public.
4059

@@ -56,7 +75,11 @@ $api->config(['timezone' => 'UTC']);
5675
$api->config()->get('timezone');
5776
```
5877

59-
## `setup(): ApiSetup`
78+
### `setup()`
79+
80+
```php
81+
setup(): ApiSetup
82+
```
6083

6184
Public access to SDK setup and extension points without adding every setup method to the concrete SDK surface.
6285

@@ -68,7 +91,11 @@ $api->setup()->auth()->bearer($token);
6891

6992
SDK authors can call the same setup methods directly from subclasses.
7093

71-
## `resource(string $class): Resource`
94+
### `resource()`
95+
96+
```php
97+
resource(string $class): Resource
98+
```
7299

73100
Protected helper for creating resource instances from an API class.
74101

@@ -82,7 +109,13 @@ final class ExampleApi extends Api
82109
}
83110
```
84111

85-
## `baseUrl(?string $baseUrl): static`
112+
## Request Defaults
113+
114+
### `baseUrl()`
115+
116+
```php
117+
baseUrl(?string $baseUrl): static
118+
```
86119

87120
Protected fluent helper for configuring the API base URL.
88121

@@ -92,15 +125,23 @@ $this->baseUrl('https://api.example.com');
92125

93126
Full request URLs passed to resources override the configured base URL.
94127

95-
## `defaultQuery(string $name, mixed $value): static`
128+
### `defaultQuery()`
129+
130+
```php
131+
defaultQuery(string $name, mixed $value): static
132+
```
96133

97134
Protected fluent helper for configuring one query parameter applied to every request.
98135

99136
```php
100137
$this->defaultQuery('api_key', $apiKey);
101138
```
102139

103-
## `defaultQueries(array $query): static`
140+
### `defaultQueries()`
141+
142+
```php
143+
defaultQueries(array $query): static
144+
```
104145

105146
Protected fluent helper for configuring query parameters applied to every request.
106147

@@ -111,18 +152,26 @@ $this->defaultQueries(['api_key' => $apiKey, 'locale' => 'en']);
111152
Query merge order is:
112153

113154
```text
114-
API defaults < endpoint options < endpoint method query argument
155+
API defaults < endpoint options
115156
```
116157

117-
## `defaultHeader(string $name, mixed $value): static`
158+
### `defaultHeader()`
159+
160+
```php
161+
defaultHeader(string $name, mixed $value): static
162+
```
118163

119164
Protected fluent helper for configuring one header applied to every request.
120165

121166
```php
122167
$this->defaultHeader('Accept', 'application/json');
123168
```
124169

125-
## `defaultHeaders(array $headers): static`
170+
### `defaultHeaders()`
171+
172+
```php
173+
defaultHeaders(array $headers): static
174+
```
126175

127176
Protected fluent helper for configuring headers applied to every request.
128177

@@ -132,50 +181,64 @@ $this->defaultHeaders(['Accept' => 'application/json']);
132181

133182
Header names are not normalized by the package.
134183

135-
## `auth(): AuthBuilder`
184+
## Pipeline Builders
185+
186+
### `auth()`
187+
188+
```php
189+
auth(): AuthBuilder
190+
```
136191

137192
Protected access to authentication configuration.
138193

139194
```php
140-
$this->auth()
141-
->bearer($token)
142-
->query('appid', $apiKey);
195+
$this->auth()->bearer($token);
143196
```
144197

145198
Authentication is applied automatically to outgoing requests.
146199

200+
Calling another auth helper replaces the previous authentication. Use `chain()` when multiple authentication rules are required.
201+
147202
See [Authentication](07-authentication.md) for helper methods, HTTPlug authentication objects, and custom auth callbacks.
148203

149-
## `hooks(): HookBuilder`
204+
### `hooks()`
205+
206+
```php
207+
hooks(): HookBuilder
208+
```
150209

151210
Protected access to request and response hooks. SDK users can access hooks through `setup()`.
152211

153212
```php
154213
$this->hooks()->beforeRequest($hook);
155214
$this->hooks()->afterResponse($hook);
156-
157-
$api->setup()->hooks()->beforeRequest($hook);
158215
```
159216

160217
Hooks are SDK-author extension points. They run around the raw HTTP request and response, before response decoding and error handling.
161218

162219
See [Hooks](12-hooks.md) for hook context objects, return values, and priority behavior.
163220

164-
## `plugins(): PluginBuilder`
221+
### `plugins()`
222+
223+
```php
224+
plugins(): PluginBuilder
225+
```
165226

166227
Protected access to HTTPlug plugin configuration. SDK users can access plugins through `setup()`.
167228

168229
```php
169230
$this->plugins()->add($plugin, priority: 16);
170-
171-
$api->setup()->plugins()->add($plugin, priority: 16);
172231
```
173232

174233
Higher priority plugins run earlier. Same-priority plugins are preserved in insertion order.
175234

176235
See [Plugins](11-plugins.md) for internal plugin order and priority guidance.
177236

178-
## `cache(CacheItemPoolInterface $pool): CacheBuilder`
237+
### `cache()`
238+
239+
```php
240+
cache(CacheItemPoolInterface $pool): CacheBuilder
241+
```
179242

180243
Protected access to PSR-6 HTTP response cache configuration. SDK users can access cache through `setup()`.
181244

@@ -184,20 +247,20 @@ $this
184247
->cache($pool)
185248
->defaultTtl(3600)
186249
->methods(['GET', 'HEAD']);
187-
188-
$api->setup()->cache($pool)->defaultTtl(3600);
189250
```
190251

191252
See [Cache](09-cache.md) for cache options and plugin order.
192253

193-
## `client(ClientInterface $client): ClientBuilder`
254+
### `client()`
255+
256+
```php
257+
client(ClientInterface $client): ClientBuilder
258+
```
194259

195260
Protected access to PSR-18 client configuration. SDK users can access client configuration through `setup()`.
196261

197262
```php
198263
$this->client($client);
199-
200-
$api->setup()->client($client);
201264
```
202265

203266
SDK authors can configure PSR-17 factories on the returned builder:
@@ -211,21 +274,29 @@ $this
211274

212275
See [HTTP Client](08-http-client.md) for client and factory configuration.
213276

214-
## `logger(LoggerInterface $logger): LoggerBuilder`
277+
### `logger()`
278+
279+
```php
280+
logger(LoggerInterface $logger): LoggerBuilder
281+
```
215282

216283
Protected access to PSR-3 logger configuration. SDK users can access logging through `setup()`.
217284

218285
```php
219286
$this
220287
->logger($logger)
221288
->formatter($formatter);
222-
223-
$api->setup()->logger($logger);
224289
```
225290

226291
See [Logging](10-logging.md) for logger formatting and cache logging.
227292

228-
## `responses(): ResponseBuilder`
293+
## Response Handling
294+
295+
### `responses()`
296+
297+
```php
298+
responses(): ResponseBuilder
299+
```
229300

230301
Protected access to response decoding configuration.
231302

@@ -244,7 +315,11 @@ Available response formats:
244315

245316
When no format is configured, `raw()` is used.
246317

247-
## `errors(): ErrorBuilder`
318+
### `errors()`
319+
320+
```php
321+
errors(): ErrorBuilder
322+
```
248323

249324
Protected access to error handling configuration.
250325

@@ -288,51 +363,75 @@ $this->errors()->when(function (ErrorContext $context): ?Throwable {
288363

289364
Status callbacks receive `ErrorContext` and must return a `Throwable`. Custom `when()` handlers receive `ErrorContext` and must return a `Throwable` when matched or `null` when not matched.
290365

291-
## `Config`
366+
## Config Object
292367

293368
`Config` stores SDK options.
294369

295-
### `all(): array`
370+
### `all()`
371+
372+
```php
373+
all(): array
374+
```
296375

297376
Returns all option values.
298377

299378
```php
300379
$options = $api->config()->all();
301380
```
302381

303-
### `only(string ...$keys): array`
382+
### `only()`
383+
384+
```php
385+
only(string ...$keys): array
386+
```
304387

305388
Returns selected option values. Missing keys are omitted.
306389

307390
```php
308391
$query = $api->config()->only('units', 'lang');
309392
```
310393

311-
### `has(string $key): bool`
394+
### `has()`
395+
396+
```php
397+
has(string $key): bool
398+
```
312399

313400
Checks whether an option exists. A key with a `null` value still exists.
314401

315402
```php
316403
$api->config()->has('timezone');
317404
```
318405

319-
### `get(string $key, mixed $default = null): mixed`
406+
### `get()`
407+
408+
```php
409+
get(string $key, mixed $default = null): mixed
410+
```
320411

321412
Returns an option value or the default when the key does not exist.
322413

323414
```php
324415
$timezone = $api->config()->get('timezone', 'UTC');
325416
```
326417

327-
### `set(string $key, mixed $value): self`
418+
### `set()`
419+
420+
```php
421+
set(string $key, mixed $value): self
422+
```
328423

329424
Sets one option value.
330425

331426
```php
332427
$api->config()->set('timezone', 'UTC');
333428
```
334429

335-
### `merge(array $values): self`
430+
### `merge()`
431+
432+
```php
433+
merge(array $values): self
434+
```
336435

337436
Sets multiple option values.
338437

0 commit comments

Comments
 (0)