Ariadocs

Code samples

Edit on GitHub

Generate request code for an endpoint in eight languages.

import { createRequestSample, createCodeSample } from "@ariadocs/openapi";

const sample = createRequestSample(operation, { securitySchemes: api.securitySchemes });

createCodeSample(sample, "curl");
createCodeSample(sample, "go");
LanguageidClient
cURLcurlcURL
JavaScriptjavascriptfetch
Pythonpythonrequests
Gogonet/http
Rustrustreqwest (blocking)
Javajavajava.net.http, Java 15 or later
KotlinkotlinOkHttp 4
C#csharpHttpClient, C# 11 or later

The sample fills in parameters from the spec's examples, or makes up values from the schema. It adds a placeholder for auth, such as Authorization: Bearer <TOKEN>, and builds the body from the request example.

Here's the result for Resend's POST /emails:

Preview
curl -X POST 'https://api.resend.com/emails' \
  -H 'Authorization: Bearer <TOKEN>' \
  -H 'Content-Type: application/json' \
  -d '{
  "from": "string",
  "to": "string",
  "subject": "string",
  "bcc": "string",
  "cc": "string",
  "reply_to": "string",
  "html": "string",
  "text": "string",
  "template": {
    "id": "string",
    "variables": {
      "variableName": "Sign up now",
      "variableName2": 123
    }
  },
  "headers": {},
  "scheduled_at": "string",
  "attachments": [
    {
      "content": "<binary>",
      "filename": "string",
      "path": "string",
      "content_type": "string",
      "content_id": "string"
    }
  ],
  "tags": [
    {
      "name": "string",
      "value": "string"
    }
  ],
  "topic_id": "string"
}'

The values come from the spec, and people paste these snippets into a terminal or an editor. So every value is escaped for its language. A quote in a cURL argument can't end the string early, a $ can't start a Kotlin string template, and a line break in a header value can't start a new header. Request bodies use each language's multi-line raw string where that's safe, so they stay readable.