Request / Response
Request/Response shows a tabbed set of request and response code examples for an endpoint, one tab per language. A reader can pick cURL, JavaScript, Python, or whichever language they work in, and see a matching request alongside the response it returns.
Adding the block#
- In the block editor, open the block inserter and search for Request / Response.
- Add it to the page, usually under an Endpoint and its Parameters block.
- Click + Add language for each language you want to show.
- For each one, pick the language, set a tab label, and paste in the request code and the response code.
Settings#
| Setting | What it does |
|---|---|
| Show line numbers | Adds line numbers to every request and response sample in the block. |
Per language tab:
| Setting | What it does |
|---|---|
| Language | Sets syntax highlighting for that tab. Covers cURL, JavaScript, Python, PHP, Ruby, Go, Java, C#, and Rust. |
| Tab label | The text shown on the tab itself, e.g. cURL or Node.js. |
| Request code | The sample request for that language. |
| Response code | The sample response that request returns. |
Example#
One language tab: Language set to cURL, Tab label set to cURL, with a request and its response.
curl -X GET https://api.example.com/v1/resource \
-H "Authorization: Bearer YOUR_API_KEY"
{
"id": "123",
"status": "ok"
}
const res = await fetch('https://api.example.com/v1/resource', {
headers: { Authorization: 'Bearer YOUR_API_KEY' }
});
const data = await res.json();
{
"id": "123",
"status": "ok"
}
The block#
In the editor, this is one language row filled in with a request and response, no shortcode needed.
The shortcode#
The same block, added as a shortcode instead, for a widget, classic-editor content, or a page builder that only accepts shortcodes. Because examples is a list of example objects, it’s passed as a JSON string:
[nahnu_code_block block="request-response"]
[{"language":"bash","label":"cURL","requestCode":"curl https://api.example.com/customers/42","responseCode":"{\"id\": 42, \"name\": \"Ada Lovelace\"}"}]
[/nahnu_code_block]
The examples attribute is wrapped in single quotes, with the strings inside it in double quotes, and any double quote that appears inside the request or response text itself is escaped with a backslash. Keeping the quote characters distinct like this is what keeps the shortcode from cutting off early.
How it renders#
A single tab labeled “cURL”, with the request shown above the response it returns.
Tips#
- Keep the request and response samples realistic. A reader will often copy the request as a starting point.
- Add cURL first, then whichever other languages your readers are most likely to use.
- Pair this block with Parameters directly above it, so a reader can see the inputs and the resulting request and response together.