Skip to content

Commit ba06dc5

Browse files
authored
docs: update API style guide (#102)
* docs: update API style guide Bringing in REST API guidance * docs: feedback implemented Clarified responsibilities around snippets (dev vs. writer) Added link to Open Payments style guide Fixed broken link in ChunkedSnippet page
1 parent 6e84d42 commit ba06dc5

File tree

3 files changed

+89
-6
lines changed

3 files changed

+89
-6
lines changed

src/content/docs/content/api.mdx

Lines changed: 87 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { Tabs, TabItem } from '@astrojs/starlight/components'
99

1010
This guide is designed for writers and contributors involved in documenting our APIs, which use both GraphQL and REST API technologies.
1111

12-
At Interledger, we maintain multiple repositories that encompass a variety of projects, each serving different purposes in our ecosystem. This style guide aims to provide a cohesive framework for documenting these APIs so that our docs are clear, consistent, and aligned with our standards.
12+
At Interledger, we maintain multiple repositories that encompass a variety of projects, each serving different purposes across our ecosystem. This style guide aims to provide a cohesive framework for documenting these APIs so that our docs are clear, consistent, and aligned with our standards.
1313

1414
## GraphQL
1515

@@ -123,7 +123,7 @@ Before this style guide was created, there were older GraphQL examples that, in
123123
}
124124
```
125125
</TabItem>
126-
<TabItem label="Arguments">
126+
<TabItem label="Variables">
127127
```json
128128
{
129129
"input": {
@@ -163,7 +163,7 @@ Before this style guide was created, there were older GraphQL examples that, in
163163
}
164164
```
165165
</TabItem>
166-
<TabItem label="Arguments">
166+
<TabItem label="Variables">
167167
```json
168168
{
169169
"input": {
@@ -191,4 +191,87 @@ Before this style guide was created, there were older GraphQL examples that, in
191191

192192
## REST API
193193

194-
Coming soon
194+
From [restfulapi.net](https://restfulapi.net/), a REST API (Representational State Transfer) provides a standardized way to interact with resources using predictable HTTP requests (GET, POST, PUT, DELETE). REST APIs are designed for interoperability and human readability, enabling developers to work with predictable resource paths and standardized data formats such as JSON. Each endpoint represents a resource, and responses use standard HTTP status codes to indicate success or failure.
195+
196+
For more in-depth information about REST APIs, take a look at the following resources:
197+
198+
- [REST API tutorial](https://restfulapi.net/)
199+
- [MDN Docs: HTTP overview](https://developer.mozilla.org/en-US/docs/Web/HTTP)
200+
- [OpenAPI specification](https://spec.openapis.org/oas/latest.html)
201+
202+
In [Open Payments](https://openpayments.dev/), REST APIs expose operations such as creating incoming and outgoing payments, requesting quotes, and handling authentication. Each follows conventional HTTP request/response semantics defined in our [OpenAPI specifications](https://github.com/interledger/open-payments-specifications).
203+
204+
### Documenting REST API examples
205+
206+
Our REST API examples appear in two primary contexts within the Open Payments docs:
207+
208+
1. [SDK pages](https://openpayments.dev/sdk/before-you-begin/): Focused, single-operation walkthroughs showing how to call individual endpoints (for example, creating an incoming payment)
209+
2. [Guide pages](https://openpayments.dev/guides/accept-otp-online-purchase/): Broader workflows that combine multiple operations into real world end-to-end use cases (for example, accept a one-time payment for an online purchase)
210+
211+
Although both types of content reference the same underlying API endpoints, the way examples are embedded and presented differs slightly. This section explains how to structure and format these examples consistently.
212+
213+
:::note
214+
When writing or updating Open Payments SDK and guide pages, refer also to the [Open Payments style guide](/content/openpayments). It defines higher‑level conventions such as naming, formatting, and guide structure that complement the REST‑specific example guidance below.
215+
:::
216+
217+
#### SDK pages
218+
219+
Each SDK page demonstrates how a single API operation is implemented across multiple SDKs. These examples are presented in a multi-language tabbed interface, where each programming language has its own `<TabItem>` component.
220+
221+
Like the GraphQL examples above, we're using the built-in Starlight [`<Tabs>` and `<TabItem>`](https://starlight.astro.build/components/tabs/) components.
222+
223+
:::tip
224+
Make sure you import the `<Tabs>` and `<TabItem>` components to your MDX file like so:
225+
226+
`import { Tabs, TabItem } from '@astrojs/starlight/components'`
227+
:::
228+
229+
##### Using the tabbed interface
230+
231+
As stated earlier, the `<Tabs>` component is wrapped around all language examples, and each language is inside its own `<TabItem>` component. Writers do not edit the code examples themselves. Developers maintain those code snippets in their respective SDK repositories, and writers embed them into SDK pages with [`<ChunkedSnippet>`](/oppm/chunkedsnippet/) components. It's our role to make sure that the structure, order, and labeling of the tabs are consistent across all SDK pages.
232+
233+
- Maintain a consistent tab order (TypeScript/JavaScript, Rust, PHP)
234+
- Each `<TabItem>` label should include both the language name and its [corresponding icon](https://starlight.astro.build/reference/icons/#all-icons) when available (for example, `icon="seti:javascript"`)
235+
- Use [`<ChunkedSnippet>`](/oppm/chunkedsnippet/) to import maintained code blocks directly from SDK repositories
236+
237+
<CodeBlock title="Simplified tabbed interface - example">
238+
````
239+
<Tabs>
240+
<TabItem label="TypeScript/JavaScript" icon="seti:javascript">
241+
<ChunkedSnippet source="..." chunk="..."/>
242+
</TabItem>
243+
<TabItem label="Rust" icon="seti:rust">
244+
<ChunkedSnippet source="..." chunk="..."/>
245+
</TabItem>
246+
<TabItem label="PHP" icon="seti:php">
247+
<ChunkedSnippet source="..." chunk="..."/>
248+
</TabItem>
249+
</Tabs>
250+
````
251+
</CodeBlock>
252+
253+
These conventions ensure a consistent presentation across all SDK examples, even as we add new languages.
254+
255+
#### Guide pages
256+
257+
Open Payments developer guides demonstrate complete workflows that combine multiple REST API operations. Each step typically shows one request/response sequence.
258+
259+
Writers should follow the broader framework in the [Open Payments style guide](/content/openpayments/#developer-guides) for page elements like the page summary, scenario, endpoints list, and the steps in the guide. That guide also defines the formatting details for [API requests](/content/openpayments/#code-for-requests) and [API responses](/content/openpayments/#code-for-responses).
260+
261+
Keep both request and response examples visually lightweight and predictable. Each should fit comfortably within a single screen view so readers can understand an operation at a glance. Refer to the following tips for both example requests and responses.
262+
263+
##### API request considerations
264+
265+
Example API requests should illustrate the endpoint, HTTP method, and relevant data.
266+
267+
- Keep payloads brief and realistic
268+
- Include the parameters that can influence the specific response being demonstrated
269+
- When different endpoints share common data (like wallet addresses or grants), display those values consistently throughout the guide so readers can easily recognize them
270+
271+
##### API response considerations
272+
273+
Example API responses should represent what relevant data comes back from the API, and it doesn't always have to include a full payload.
274+
275+
- Emphasize what changed or what was created as a result of the request (for example, a new ID that was generated or a status that changed)
276+
- Trim unrelated fields to keep the focus on the result shown
277+
- Follow the same component pattern as SDK pages: a `<details>` block labeled "Example response" containing a short explanatory line and a `json wrap` block that matches the OpenAPI spec

src/content/docs/content/openpayments.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ If the guide mentions optional APIs, exclude them from this list. This list is w
127127
Request snippets should come from a developer. If the developer is nice enough to add the snippets to the doc, review the markdown to make sure it's formatted correctly.
128128

129129
* Each step should use a synced Tabs component (`<Tabs syncKey="lang">`).
130-
* Each language should have its own tab and include the lang's icon, if available.
130+
* Each language should have its own tab and include the [lang's icon](https://starlight.astro.build/reference/icons/#all-icons), if available.
131131
* Each code block should specify the lang and use the `wrap` property (` ```ts wrap `).
132132

133133
Update each snippet, when possible, to be specific to your scenario. Look at other guides for examples. You might need a developer to help with parts of it.

src/content/docs/oppm/chunkedsnippet.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ Use the `<ChunkedSnippet>` component within your content like so:
3333

3434
## Working example
3535

36-
Refer to the TypeScript code snippets within the Open Payments documentation for [Get wallet address information](https://openpayments.guide/snippets/wallet-get-info/#prerequisites). The raw source file is located [here](https://raw.githubusercontent.com/interledger/open-payments-snippets/main/wallet-address/wallet-address-get.ts).
36+
Refer to the TypeScript code snippets within the Open Payments documentation for [Get wallet address information](https://openpayments.dev/sdk/wallet-get-info/). The raw source file is located [here](https://raw.githubusercontent.com/interledger/open-payments-snippets/main/wallet-address/wallet-address-get.ts).

0 commit comments

Comments
 (0)