APIs

How to Test a REST API from Your Browser

By Laxmi SolutionsPublished 3 min read

Testing an API used to mean installing a desktop client or wrestling with long curl commands. An HTTP client in the browser does the same job: build a request, send it, and read the status, headers and body. Here's a quick workflow, from a first GET to authenticated requests you can share as curl.

Send your first request

  1. Open the editor and the HTTP client from the activity bar.
  2. Choose a method (GET, POST, PUT, PATCH, DELETE, HEAD or OPTIONS) and enter the URL.
  3. Add query parameters in the Params tab, or type them into the URL.
  4. Send, then read the status code, response time and size, and the body and headers.

JSON responses are pretty-printed and highlighted, and you can open a response in an editor tab to search it, fold it, or compare it with another response in the diff view.

Status codes at a glance

Common HTTP status codes
CodeMeaningUsual cause
200 / 201 / 204OK / Created / No contentSuccess
301 / 302 / 304Moved / Found / Not modifiedRedirects and caching
400Bad requestMalformed body or missing field
401 / 403Unauthorised / ForbiddenMissing or wrong credentials / not allowed
404Not foundWrong path or ID
415 / 422Unsupported media type / UnprocessableWrong Content-Type / validation failed
429Too many requestsRate limited; wait and retry
500 / 502 / 503Server error / Bad gateway / UnavailableA problem on the server side

Sending JSON and form data

For POST, PUT and PATCH, choose a body type: JSON, raw text, form-data, URL-encoded or GraphQL. With JSON the client sets Content-Type: application/json for you, which is the most common thing to forget when a server answers 415 or ignores the body.

{
  "title": "Buy milk",
  "done": false
}

Authentication

  • Bearer token: sends Authorization: Bearer <token>, the usual choice for OAuth and JWT APIs.
  • Basic auth: a username and password, encoded into the Authorization header.
  • API key: a named key sent as a header or as a query parameter, whichever the API documents.

Keep secrets out of the URL where you can: URLs end up in logs and browser history, headers usually don't.

Environment variables

Put values you reuse (a base URL, a token) in the Env tab and reference them as {{NAME}} anywhere in the URL, headers or body. Switching from staging to production is then one value, not twenty edits:

GET {{BASE_URL}}/v1/todos?limit=10
Authorization: Bearer {{TOKEN}}

Import and export curl

API docs usually show examples as curl. Paste one into the curl import and the method, URL, headers and body are filled in. Going the other way, Copy as curl gives a command with your variables and auth already filled in, ready for a terminal or a bug report.

curl -X POST "https://api.example.com/v1/todos" \
  -H "Content-Type: application/json" \
  -d '{"title":"Buy milk","done":false}'

CORS, redirects and timeouts

A request made by a web page's own JavaScript is subject to CORS, so many APIs refuse it. Code Editor's HTTP client sends requests through its server instead, so CORS doesn't block them, the same as a desktop client. For the same reason it refuses private and local addresses (localhost, 192.168.x.x), so use curl for APIs running on your own machine.

  • Follow redirects is on by default; turn it off to inspect a 301 or 302 itself.
  • The timeout is 30 seconds by default and can be set from 1 to 120.
  • Recent requests are kept in a history so you can resend them.