# cURL → Node.js and Python converter

> Every endpoint page and the playground give you a curl command. Paste one here - edited or not - and get the equivalent Node.js and Python code, checked against the endpoint's schema before you run it.

Source: https://astronode.dev/tools/curl-to-code · Updated: 2026-12-01

The interactive tool runs in the browser at https://astronode.dev/tools/curl-to-code; this file is its explanation.

## What gets translated

*curl flags the converter understands*

| curl | Becomes |
| --- | --- |
| `-X` / `--request` | the HTTP method (GET or POST) |
| `-H 'Authorization: Bearer …'` | a header read from `ASTRONODE_API_KEY` |
| `-d`, `--data`, `--data-raw`, `--json` | the JSON body (`json=` in Python, `JSON.stringify` in Node) |
| `-s`, `-N`, `--compressed`, `-L` | ignored - they do not change the request |
| `-u`, `-F`, `-T`, `-b` | reported as not translated |

Quoting follows POSIX shells: single quotes, double quotes, `'\''` escapes and backslash line continuations - the forms AstroNode's own snippets use. Windows `cmd.exe` `^` continuations are not supported; paste the command as one line or use the PowerShell form.

## The generated code

Node.js (18+, built-in fetch) - the same generator the endpoint pages use:

```javascript
const res = await fetch("https://api.astronode.dev/v1/charts/birth", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.ASTRONODE_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({ /* your body */ }),
});
if (!res.ok) throw new Error(`AstroNode ${res.status}: ${await res.text()}`);
const { data } = await res.json();
```

Python uses `requests` with `timeout=30` and `raise_for_status()`. Neither version needs an SDK. Chat endpoints return their fields at the top level, so for those the code prints the whole JSON instead of `data`.

## Checks before you run it

- **Host** - is it the AstroNode API or chat origin?
- **Endpoint** - does the path exist, and with this method? `GET /v1/charts/birth` is caught before it becomes a 404.
- **Body** - every top-level field is compared with the endpoint's schema; unknown fields (a `400 VALIDATION_ERROR` waiting to happen) and missing required ones are listed.
- **Key** - a pasted `aie_live_…` or `aie_test_…` key is never copied into the code, and you are told to rotate it if it has been shared.

## Common mistakes

- **Hard-coding the key** while translating by hand. Read it from the environment, and keep the call on your server.
- **Sending the body as form data.** `requests.post(url, data=...)` form-encodes a dict; the API needs `json=`.
- **Dropping `Content-Type`** in Node. Without `application/json` the body is not parsed as JSON.
- **No timeout in Python.** `requests` waits forever by default; the generated code sets 30 seconds.

## FAQ

**Is my curl command or key sent anywhere?**

No. Parsing and code generation happen in your browser.

**Which languages are supported?**

Node.js (built-in `fetch`) and Python (`requests`), matching the tabs on every endpoint page. For other languages, the [request builder](https://astronode.dev/tools/request-json-builder) gives you the JSON body to send.

**Does it work for GET endpoints with path parameters?**

Yes - a path such as `/v1/horoscope/daily/aries` is matched to its endpoint and kept as written.

## Related endpoints

- [`POST /v1/charts/birth`](https://astronode.dev/capabilities/vedic/charts-birth) - Birth Chart (Kundli) API
- [`GET /v1/horoscope/daily/:sign`](https://astronode.dev/capabilities/western/horoscope-daily-sign) - Daily Sun Sign Horoscope API
- [`POST /v1/chat/respond`](https://astronode.dev/capabilities/chat/chat-respond) - AI Astrologer Chat API
