Supported languages and libraries
| Language | Targets |
|---|---|
| Shell | cURL, Wget, HTTPie, PowerShell (Invoke-RestMethod) |
| Raw | HTTP request text |
| JavaScript | Fetch, Axios, jQuery, XHR |
| Node.js | native http, Axios |
| Python | Requests, http.client |
| Go | net/http |
| Java | OkHttp, Unirest, java.net.http |
| C# | HttpClient, RestSharp |
| PHP | cURL, Guzzle |
| Ruby | Net::HTTP |
| Swift | URLSession |
| Kotlin | OkHttp |
| Dart | http |
| Rust | reqwest |
| C | libcurl |
| R | httr, RCurl |
| OCaml | Cohttp |
Variables and auth resolved for you
Turn on variable resolution and snippets are generated with your current values substituted, so {{baseUrl}}/users/{{userId}} becomes a real URL; leave it off to keep the {{placeholders}}. The request's auth, including auth inherited from its folder or collection, is applied: a Bearer token becomes an Authorization header and an API key lands in the header or query string you configured. Generating code never sends the request.
For example, a JSON POST with a bearer token as Python Requests:
import requests
url = "https://api.example.com/v1/orders"
payload = {"sku": "A-1", "quantity": 2}
headers = {
"Content-Type": "application/json",
"Authorization": "Bearer eyJhbGciOi...",
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)Every body type
Snippets cover JSON and other raw bodies, x-www-form-urlencoded fields, multipart form-data with file fields, binary bodies and GraphQL queries with variables, each written the idiomatic way for the chosen library where it has one.
Code samples in published docs
The same generator powers the code samples in published API documentation. Readers choose their language and get a snippet for every request, so your docs and the app never disagree.
Go the other way: paste cURL
Code generation has a natural counterpart: paste a cURL command into the import dialog (or straight into the URL bar) and Swastik Codes turns it into a request with the same method, headers and body. That makes it easy to move a request between a terminal, a teammate's message and your collection. See import and export.
How it works
- Open any request in the app.
- Open the code snippet panel and pick a language.
- Copy the snippet into your code or terminal. When you are ready to send from Swastik Codes itself, create a free account.
Frequently asked questions
Does the snippet include my secrets?
If you generate with variables resolved, the snippet can contain the real values, including tokens. Be careful where you paste it, and rotate any token that ends up in a public place.
Which cURL flags are generated?
The method, headers, body (--data, --form or --data-binary as appropriate) and URL, quoted for a POSIX shell. PowerShell has its own target.
Can I generate a full SDK?
No. Code generation produces a snippet per request. For a full client library, export your collection to OpenAPI 3 and use an OpenAPI code generator.
Is gRPC code generation supported?
For gRPC requests you can copy a grpcurl command from the gRPC client.