Utvikling · verktøy

Lag API-forespørselskode – cURL og Fetch

Beskriv en forespørsel og kopier kode til terminalen eller JavaScript-prosjektet ditt; denne siden sender ikke forespørselen.

Kjøres i nettleseren. Ingen opplasting.

This tool builds code only. It does not send a request.

Browser CORS and server rules can block a request you run elsewhere.

No network request was sent.

Om verktøyet

Lag API-forespørselskode – cURL og Fetch sem complicação.

De genererte eksemplene er bare lokal tekst. CORS i nettleseren, autentisering, serverregler og nettverkstilgang kan påvirke forespørsler du kjører et annet sted. Ikke lim inn hemmeligheter på delte enheter.

Veiledning

Slik bruker du Lag API-forespørselskode – cURL og Fetch

The API Request Builder writes the code for an HTTP request so you can copy it. You choose a method, type a URL, add headers as JSON and an optional body, and pick cURL or JavaScript Fetch. The page only builds the text. It never sends the request, so you will not see a response, and it does not check whether the address or the server exists.

Slik gjør du

  1. Pick an HTTP method and type a full http or https URL.
  2. Choose cURL or JavaScript Fetch as the output format.
  3. Add headers as a JSON object, for example {"Content-Type": "application/json"}, and type a body if the method allows one.
  4. Press Build code, then Copy code, and run it yourself in a terminal or a script.

Eksempler

A simple GET as cURL

Du skriver inn
Metode
GET
URL
https://api.example.test/items
Utdataformat
cURL
Du får
Kodespråk
curl --request GET 'https://api.example.test/items'

With no headers or body the command has only the method and the quoted address.

Kjørt med verktøyets egen kode.

A JSON POST as cURL

Du skriver inn
Metode
POST
URL
https://api.example.test/items
Headere
{"Content-Type":"application/json"}
Forespørselskropp
{"name":"Pen","qty":2}
Utdataformat
cURL
Du får
Kodespråk
curl --request POST --header 'Content-Type: application/json' --data-raw '{"name":"Pen","qty":2}' 'https://api.example.test/items'

Each header becomes a --header option and the body goes into --data-raw. Everything is wrapped in single quotes so a shell reads it as one piece.

Kjørt med verktøyets egen kode.

The same POST as Fetch

Du skriver inn
Metode
POST
URL
https://api.example.test/items
Headere
{"Content-Type":"application/json"}
Forespørselskropp
{"name":"Pen","qty":2}
Utdataformat
JavaScript Fetch
Du får
Kodespråk
fetch("https://api.example.test/items", { "method": "POST", "headers": { "Content-Type": "application/json" }, "body": "{\"name\":\"Pen\",\"qty\":2}" });

The options object holds the method, the headers and the body as a string. The tool does not add a Content-Type header for you, so type it in the headers box when you need one.

Kjørt med verktøyets egen kode.

A GET with a body

Du skriver inn
Metode
GET
URL
https://api.example.test/items
Forespørselskropp
{"a":1}
Du får
Melding
Enter the requested values and try again.

GET and HEAD requests cannot carry a body here, so the tool shows an error instead of code. Other problems that give the same message are a URL without http or https, a URL with a user name and password in it, and headers that are not a JSON object.

Kjørt med verktøyets egen kode.

Når det er nyttig

  • Turn an API example from documentation into a cURL command you can run in a terminal.
  • Get a Fetch snippet to paste into a small script and then edit.
  • Check how a method, headers and body fit together before you write code by hand.
  • Share a request with a colleague as text, using a placeholder instead of a real token.

Begrensninger

  • The tool sends nothing. It cannot test an endpoint, show a response, or tell you whether the request would work.
  • The URL must start with http or https and must not hold a user name or password. Up to 4,096 characters are allowed.
  • At most 40 headers are allowed, header names must be valid, a value is limited to 2,048 characters and must not contain line breaks. The body is limited to 100,000 characters.
  • Requests run from a browser can still be blocked by CORS, and authentication or server rules may reject them. Check the API's own documentation.

Tips

  • General security advice: do not paste real API keys, tokens or passwords into any online page. Use a placeholder such as YOUR_TOKEN_HERE and put the real value in only when you run the code.
  • General security advice: if a real token was pasted or shared by mistake, revoke it and make a new one, since it may have been copied or logged.
  • Use example or test domains while you learn, and read the API's documentation for the exact headers it needs.

Kilder

Vanlige spørsmål

Sobre Lag API-forespørselskode – cURL og Fetch.

Does this tool send my request?

No. The page says it builds code only and sends no network request. Press Copy code and run the result yourself in a terminal, a script or the browser console. Nothing on the page contacts the address you typed.

Should I put my real API key or token in the headers box?

General security advice: avoid it. Use a placeholder like Bearer YOUR_TOKEN_HERE in the tool and add the real value only where you run the code. A real token in copied text can end up in chat logs, notes or shell history.

What is the difference between the cURL and Fetch output?

cURL is a command for a terminal. Fetch is JavaScript code for a browser or a recent Node.js version. Both describe the same request. Pick the one that matches where you plan to run it.

Why does it say I cannot use a body with GET?

This tool does not allow a body on GET or HEAD requests and shows an error if you add one. Use POST, PUT, PATCH or DELETE if you need a body, or put the data in the URL query.

Does it add a Content-Type header for me?

No. If you need Content-Type: application/json, type it into the headers box as JSON. Without it the server may not read your body as you expect.

Why was my URL changed in the output?

The address is cleaned by the browser URL parser. For example a space in a query becomes %20, and a bare domain with no http or https is refused. Check that the output address matches what you meant.

Is what I type uploaded?

The page says the code is built locally and that your input is not uploaded. Even so, avoid pasting secrets, especially on a shared or public computer, as the page itself advises.

Hvordan bruker du API-forespørselsbygger?

Beskriv en forespørsel og kopier kode til terminalen eller JavaScript-prosjektet ditt; denne siden sender ikke forespørselen.

Lastes dataene mine opp til en server?

Nei. Behandlingen skjer i nettleseren din, og opplysningene dine lastes ikke opp.