Try It
Try It is a live request console. A visitor can edit the method, URL, headers, and body right on the page, send a real request, and see the actual response, all from their own browser. The request goes straight from the visitor’s browser to the URL you set, not through wpcodeapiblock.com’s server.
Adding the block#
- In the block editor, open the block inserter and search for Try It.
- Add it to the page, usually under the Endpoint block it’s testing.
- Set the method, default URL, default headers, and default body a visitor will see when they first open the console.
- Review the warning text and adjust it if needed.
Settings#
| Setting | What it does |
|---|---|
| Method | GET, POST, PUT, PATCH, or DELETE. The default method a visitor sees, which they can change. |
| Default URL | The URL the console starts with. Defaults to https://api.example.com/v1/resource. |
| Default headers | One Name: Value pair per line. Defaults to Authorization: Bearer YOUR_API_KEY. |
| Default body | Starting request body, for non-GET requests. |
| Warning text | Shown above the console. Defaults to a note that the request is sent directly from the visitor’s browser, not through this site’s server. |
Everything here is just a starting point. Visitors can edit the URL, headers, and body before sending.
Example#
Method set to GET, Default URL set to https://api.example.com/v1/customers, Default headers set to Authorization: Bearer YOUR_API_KEY.
The block#
In the editor, this is the Try It block’s settings panel filled in as above, no code required.
The shortcode#
The same block, added as a shortcode instead, for a widget, classic-editor content, or a page builder that only accepts shortcodes. Every setting here is a plain value, not a JSON array, so it can go in a quoted attribute as usual:
[nahnu_code_block block="try-it" method="GET" url="https://api.example.com/v1/customers" headers="Authorization: Bearer YOUR_API_KEY"]
The block attribute picks which block to render (try-it here); everything else maps to that block’s own setting by name.
How it renders#
A warning line, then a GET badge with the URL, and an editable console below it where a visitor can change the method, URL, headers, or body and send a real request.
Tips#
- Never put a real, working API key or secret in the default headers or body. Anyone viewing the page can see and use it. A placeholder like
YOUR_API_KEYis the safe default for a reason. - Point this at a sandbox or test environment when you have one, so visitors experimenting with it can’t affect real data.
- Keep the warning text honest about what the console actually does. It’s what tells a visitor the request leaves their own browser directly, not this site.