Request Code Generator

Describe one HTTP request and copy it in the language you need. Nothing is sent: this page only writes code, it never makes the request.

How it works

You fill in one request: the method, the URL, any headers, optional Basic authentication, and a body. The page writes that same request in seven forms: a cURL command, JavaScript fetch, Axios, an HTTPie command, Python with requests, Go with net/http, and PHP with its curl extension.

Every target sends the body exactly as you typed it, as a string. A JSON body is not parsed and rebuilt, because reformatting changes the bytes, and the bytes are what a server signs, hashes and compares.

The code is written on this page as you type. The request itself is never sent from here, so tokens and passwords in the form stay on your device. To actually send it from the browser, use the HTTP Client.

How to use it

  1. 1 Pick the method and type the full URL, including https://.
  2. 2 Add headers with Add header, one name and one value per row. Rows with no name are skipped.
  3. 3 Tick Basic authentication if the API wants a user name and password, and type the body if the request has one.
  4. 4 Pick a language and copy the code, or download it as a file.

Good to know

  • Each target uses its own way of saying Basic credentials: -u for cURL, -a for HTTPie, auth for Axios and requests, SetBasicAuth for Go and CURLOPT_USERPWD for PHP. fetch has none, so it gets the Authorization header worked out for you.
  • fetch() refuses a body on GET and HEAD. If you give one, the fetch code says it left the body out rather than writing code that throws.
  • For HEAD, the cURL command uses --head. curl -X HEAD waits for a body that never comes and hangs.
  • The HTTPie command uses --raw, which needs HTTPie 3.2 or newer.

Browser support

  • Chrome 94 and later
  • Firefox 93 and later
  • Safari 16.4 and later
  • Edge 94 and later

These are the oldest versions with everything the tool uses. They are worked out from the tool itself, so they change when it does.

Version numbers checked on 2026-09-04.

One request, seven dialects: what changes and what must not

Take a small request and follow it into each language. It is a POST to https://api.example.com/items, with one header, Content-Type: application/json, and the body {"name":"café"}. In cURL it becomes curl 'https://api.example.com/items' with -H 'Content-Type: application/json' and --data-raw '{"name":"café"}'. There is no -X POST, because curl switches to POST by itself as soon as a command carries data. Adding -X anyway is harmless here but forces the method onto every redirect as well, which is why the generator only writes it when the method is not the one curl would choose on its own.

The body is where most hand-written conversions go wrong. A tempting shortcut is to parse the JSON and write it as a native object: a JavaScript object for fetch, a dict for Python. That changes the request. Key order, spacing and number formatting can all come out different, and an API that signs requests or checks a hash of the body will then refuse it. So every target here sends the body as the exact string you typed. In fetch that is body: '{"name":"café"}', in Go it is strings.NewReader("{\"name\":\"café\"}"), and in PHP it is CURLOPT_POSTFIELDS with the same text. Only the quoting differs, and the quoting is the part each language is strict about.

Quoting is a rule per language, not a guess. A shell command wraps text in single quotes, and a single quote inside it has to be closed, escaped and reopened, which is why a header like X-Note: it's becomes 'X-Note: it'\''s' in the cURL and HTTPie output. JavaScript and Python escape the quote with a backslash. Go strings use double quotes and escape those instead. PHP single-quoted strings treat everything literally except a backslash and the quote itself, so line breaks in a body are written as real line breaks. The generator tests each of these against hand-written expected output, and checks that the cURL it writes parses back into exactly the request you filled in.

Credentials show the languages at their most different. Suppose the user is alice and the password is pa:ss. cURL takes -u 'alice:pa:ss' and HTTPie takes -a with the same text; curl splits on the first colon only, so a colon inside the password is safe. Axios has an auth option, requests has auth=('alice', 'pa:ss'), Go has req.SetBasicAuth and PHP has CURLOPT_USERPWD. fetch has no such option, so the generator works the header out itself: the UTF-8 bytes of alice:pa:ss in Base64 are YWxpY2U6cGE6c3M=, and the header is Authorization: Basic YWxpY2U6cGE6c3M=. You can check that with the Base64 tool on this site.

There are limits, and it is better to know them before pasting code into a project. The body is text, so multipart forms and file uploads are not generated. The code is a starting point with plain error handling: Go panics on an error and PHP prints curl_error. It also cannot know whether the server will accept the request. Headers like Host or Content-Length are written as you typed them, and some clients, browsers especially, will refuse or override those. What the tool does promise is narrower and more useful: every version says the same method, URL, headers, credentials and body bytes, so switching languages never changes the request.

Frequently asked questions

Does this page send my request anywhere?

No. It only turns the form into text. No request is made to the URL you type, and nothing you type is sent to YappyKit. If you want to send the request, the HTTP Client page does that directly from your browser to the URL.

Why is there no -X POST in the cURL command?

Because curl already sends POST when a command has a body, and writing -X POST as well is the most common way people get redirected requests wrong: -X forces the method on every redirect too. The generator writes -X only when the method is not the one curl would pick.

Why does the Python code call .encode("utf-8") on my body?

It does that only when the body has characters outside plain ASCII, such as é or an emoji. Passing UTF-8 bytes means the same bytes are sent whatever versions of requests and urllib3 are installed, instead of leaving the encoding to the library.

Can it build multipart file uploads?

No. The body here is text. A multipart form with files needs a file on the machine that runs the code, and each language builds it differently, so this tool leaves it out rather than writing code that only looks right.

Is the Basic authentication header safe to share?

No. Basic credentials are only Base64, which anyone can decode back to the user name and password. Treat generated code that contains them like the password itself.

Related tools

Your files are processed on your device and are not uploaded. You can verify this in your browser’s developer tools under the Network tab.