Mindfulness

Run REST API Calls from Browser: Quick Guide

Updated · By the Relaxmid editors

Reading time
3 min
Sections
7
Topic
Mindfulness

Most people want to test a REST API by sending a GET request directly from the browser address bar. This works only for simple, public endpoints that allow cross-origin requests. For POST, PUT, DELETE or authenticated calls, use browser developer tools or extensions instead.

Basic GET Requests

You can run a basic GET request by typing the full API URL into the browser’s address bar. This only works if the server allows cross-origin resource sharing (CORS) and does not require authentication.

  1. Copy the full REST API endpoint URL, starting with https://.
  2. Paste it into the browser address bar and press Enter.
  3. View the raw JSON or XML response on the resulting page.

If the server blocks the request, you see an error like ‘CORS blocked’ or a blank page. This means the API requires a different method.

Using Browser Developer Tools

For requests beyond GET, or when CORS blocks direct access, use the browser’s built-in developer tools. These let you inspect network traffic and manually trigger API calls from the browser context.

  1. Open developer tools with F12 or Ctrl+Shift+I (Cmd+Option+I on Mac).
  2. Go to the Network tab and trigger a page action that calls the API (e.g. clicking a button).
  3. Find the API request in the list by its name or method (GET, POST).
  4. Right-click the request and select ‘Copy as fetch’ or ‘Copy request URL’.
  5. Paste the code into the Console tab and press Enter to re-run it.

This method sends the request with the same cookies and headers as the current session, bypassing CORS restrictions. It works for authenticated APIs used by web apps you’re logged into.

API Call Settings and Limits

Request Type Browser Address Bar Developer Tools Extensions
GET (public) Yes Yes Yes
GET (authenticated) No Yes Yes
POST, PUT, DELETE No Yes (via fetch) Yes
Custom headers No Yes Yes
CORS restrictions Blocked Bypassed with session Can be disabled in extension

Browser extensions like ‘RESTClient’ or ‘Dev HTTP Client’ run full API calls with custom methods, headers, and body content. They are useful for testing during development but not enabled by default.

Common Errors and Fixes

Direct API calls from the browser often fail due to security policies. Below are common issues and how to resolve them.

Symptom Most Likely Cause Fix
Blank page or error after pasting URL CORS policy blocks request Use developer tools or extension instead
‘No ‘Access-Control-Allow-Origin’ header’ error Server does not allow browser access Test from server-side code or use proxy
401 Unauthorized Missing login session or token Run call from same site after logging in
405 Method Not Allowed Server rejects GET for that endpoint Use POST via fetch or extension
Payload too large for URL Data sent in GET query string Switch to POST with request body

Always check the browser’s developer console for detailed error messages. Network tab logs show request headers, status codes, and response bodies, helping you confirm success or debug failures.

How to Confirm It Worked

A successful API call returns structured data (usually JSON) and an HTTP status code of 200 (OK), 201 (Created), or 204 (No Content).

  1. Check the response format: valid JSON starts with { or [.
  2. Look for a 2xx status code in the Network tab.
  3. Verify expected data is present (e.g. user ID, message count).

If the response is HTML or a login page, the API call redirected due to missing authentication. Log in first, then retry using developer tools to preserve session context.

Testing APIs for Development and Debugging

Developers often need to test APIs during web app creation. While browsers have limits, combining developer tools with temporary extensions allows full testing without backend code.

To simulate form submissions, copy the fetch command from a real interaction, then modify the body data. For example, change "email": "test@example.com" to a new value and re-run.

Never store API keys or tokens in browser extensions. Clear them after testing. Disable extensions when not in use to reduce security risk.

If you’re building a frontend that consumes an API, test endpoints first using these browser methods before writing JavaScript code. This confirms the API works as documented.

Related

General information for everyday wellbeing, not medical advice. If something affects your health, sleep or mood for more than a short while, talk to a qualified professional. Read more

Spotted an error? Tell us and we will correct it (corrections policy).