curl https://api.example.com/users
curl-X POST -H'Content-Type: application/json'-d'{"name":"Ada"}' https://api.example.com/users
curl-o release.tar.gz-L https://github.com/proj/repo/archive/v2.1.tar.gz
Note -o saves to a file, -O uses the remote filename. -L follows redirects (essential for GitHub downloads). -s silences progress bar. -I fetches only headers. -k skips TLS verification (use only for debugging, never in production).
// GET requestconst res =awaitfetch("/api/products");const products =await res.json();// POST requestconst created =awaitfetch("/api/products",{
method:"POST",
headers:{"Content-Type":"application/json"},
body:JSON.stringify({ name:"Widget", price:29.99}),});if(!created.ok)thrownewError(`HTTP ${created.status}`);
Note fetch() does NOT reject on HTTP error status codes (404, 500). Always check response.ok or response.status. The body can only be consumed once.
Frequently asked questions
How does Bash & Linux handle post request?
This task is covered in 2 stacks on this page: Bash & Linux, JavaScript. The "Transfer Data with URLs" snippet in Bash & Linux uses `curl [options] URL`.
Which command does the Bash & Linux example use?
The "Transfer Data with URLs" snippet uses `curl [options] URL`, from the Networking section of the Bash & Linux cheat sheet.
Which stacks cover "post request" on this page?
Bash & Linux, JavaScript. Together they hold 2 copy-ready snippets for this task.
Is there anything to watch out for?
Yes. For "Transfer Data with URLs": -o saves to a file, -O uses the remote filename. -L follows redirects (essential for GitHub downloads). -s silences progress bar. -I fetches only headers. -k skips TLS verification (use only for debugging, never in production).