Common HTTP tasks — JSON requests, auth, file upload, retries — as ready-to-use curl and fetch code.
When you hit 429 Too Many Requests (rate limiting), wait and retry with exponential backoff instead of hammering the server.
Put a timeout on a request so you never hang forever on a slow or unresponsive server. Most defaults are effectively infinite, so set one explicitly.
Request a compressed response via `Accept-Encoding` to cut transfer size dramatically — especially effective for large JSON and text responses.
Consume Server-Sent Events (SSE, `text/event-stream`), where the server pushes a continuous stream of events down a single open connection.
POST a query and its variables to a GraphQL endpoint to fetch exactly the fields you need in a single request.
Send an access token issued by OAuth 2.0, JWT, or similar in the `Authorization: Bearer` header. This is the most common API authentication scheme today.
HTTP Basic authentication sends your username and password as a base64-encoded `user:pass` string.
A conditional GET: send back the ETag you received earlier via `If-None-Match`, and if the resource is unchanged you get just a 304 Not Modified, saving bandwidth.
Resume an interrupted download by requesting only the bytes after what you already have, using the `Range` header and 206 Partial Content.
Check the status code and response headers without downloading the body — handy for auditing cache policy, content type, and redirects.
Print the actual request/response headers and even the TLS handshake so you can see exactly what is happening and why.
Skip TLS certificate verification to reach a local dev server using a self-signed cert. Use this in development only.
Reproduce the CORS preflight (OPTIONS) that a browser sends before a cross-origin request, using curl to verify the server's CORS configuration.
Measure how long each phase of a request takes (DNS, connect, TLS, first byte, total) to pinpoint where latency comes from.
Upload a file alongside text fields using `multipart/form-data` — the same mechanism a browser file-upload form uses.
Fetch a remote file and save it to disk. Works for images, PDFs, binaries — any file type.
The most fundamental recipe: issue a GET request and parse the JSON body the server returns. It is read-only and carries no request body.
POST a JSON body to create a new resource. On success you typically get back 201 Created plus the resource that was created.
Use PUT to replace a resource wholesale with a new representation. The body you send becomes the resource's complete new state.
Use PATCH to change only some fields of a resource. Send just the fields you want to modify; everything else is left untouched.
Remove the target resource with the DELETE method. On success you usually get a bodyless 204 No Content.
How to follow a 3xx response's `Location` header to the final destination, and conversely how to observe redirects without following them.
Attach arbitrary custom headers to a request — useful for request-tracing IDs, API versions, language preferences, and more.
Store cookies the server sends and automatically replay them on later requests — essential for session-based login flows.
Send form data as `application/x-www-form-urlencoded` — the classic HTML form encoding, also used by OAuth token endpoints and similar APIs.