Make an authenticated HTTP request using Basic Auth credentials.
Code
Utilitiesconst username = 'myuser';
const password = 'mypassword';
const credentials = btoa(`${username}:${password}`);
const response = await fetch(`https://httpbin.org/basic-auth/${username}/${password}`, {
headers: {
'Authorization': `Basic ${credentials}`
}
});
await response.json();Browser·fetch() may be limited by CORS
How It Works
- Combine username and password with colon:
user:pass - Base64 encode the string using
btoa() - Send in
Authorizationheader withBasicprefix - httpbin validates credentials and returns auth status
More JavaScript Snippets
Add Query Parameter
Add or update a query parameter in a URL string.
Bearer Token Authentication
Make an authenticated HTTP request using Bearer token for JWT or OAuth.
Check Cloudflare Cache Status
Check if a resource is served from Cloudflare's cache by inspecting the CF-Cache-Status header.
CORS Cross-Origin Request
Make a cross-origin HTTP request with CORS headers inspection.
Delayed Response (Test Timeouts)
Request a delayed response to test timeout handling with AbortController.
Download Binary File
Download an image or binary file and convert it to a blob or base64.