October 9th, 2025

Accessing Protected Routes

How to access routes secured with HTTP Basic Authentication in TezX.

This guide demonstrates how to access routes secured with HTTP Basic Authentication using various tools and libraries.


Using cURL

curl -u username:password http://localhost:3000/protected

Option 2: Manually set the Authorization header

curl -H "Authorization: Basic $(echo -n 'username:password' | base64)" http://localhost:3000/protected

✅ The -u flag automatically encodes credentials in Base64.


Using Postman

  1. Open a new request in Postman.
  2. Navigate to the Authorization tab.
  3. Select Basic Auth as the type.
  4. Enter your username and password.
  5. Click Send.

Postman automatically encodes and adds the Authorization header.


Using JavaScript (Fetch API)

const username = "admin";
const password = "password123";

fetch("http://localhost:3000/protected", {
  method: "GET",
  headers: {
    Authorization: `Basic ${btoa(`${username}:${password}`)}`,
  },
})
  .then((res) => res.json())
  .then((data) => console.log(data))
  .catch((err) => console.error("Error:", err));

🔍 btoa() encodes credentials in Base64 format.


Using Axios

const axios = require("axios");

axios
  .get("http://localhost:3000/protected", {
    auth: {
      username: "admin",
      password: "password123",
    },
  })
  .then((res) => console.log(res.data))
  .catch((err) => console.error("Error:", err));

💡 The auth option in Axios handles Base64 encoding internally.