← Back to Sample APIs

Addition — With Basic Authentication

Adds two integers, but requires HTTP Basic Auth before responding. The client encodes username:password in Base64 and sends it in the Authorization header.

Concept: HTTP Basic Authentication · Username + Password
Addition API Series — same operation, different style
01

Endpoint

GET https://labs.lowcademy.com/apis/add-basic?input1=5&input2=3
PropertyValue
MethodGET
Fileadd-basic.php
AuthenticationHTTP Basic Auth
Input styleURL query parameters
02

Authentication — Basic Auth

Basic Auth encodes username:password as Base64 and sends it in the Authorization: Basic <encoded> header. Most HTTP clients handle this automatically when you choose "Basic Auth".

Lab Credentials — For Training Use Only

Usernameadmin
Password1234
EncodedYWRtaW46MTIzNA==
03

Query Parameters

ParameterTypeRequiredDescription
input1IntegerRequiredFirst integer to add
input2IntegerRequiredSecond integer to add
04

Sample Requests

cURL (Basic Auth shorthand)

curl -u admin:1234 https://labs.lowcademy.com/apis/add-basic?input1=5&input2=3

cURL (manual header)

curl -H "Authorization: Basic YWRtaW46MTIzNA==" \
     https://labs.lowcademy.com/apis/add-basic?input1=5&input2=3

JavaScript (fetch)

const res = await fetch('https://labs.lowcademy.com/apis/add-basic?input1=5&input2=3', {
  headers: { 'Authorization': 'Basic ' + btoa('admin:1234') }
});
const data = await res.json();

OutSystems — Basic Authentication

// In Consume REST API → Authentication → Basic Authentication
// Username: admin
// Password: 1234
// OutSystems encodes and sends the Authorization header automatically
05

Response — 200 OK

{
  "success"    : true,
  "auth_method": "Basic Auth",
  "operation"  : "addition",
  "input1"     : 5,
  "input2"     : 3,
  "result"     : 8
}
06

Error Responses

200
OK — Result returned.
401
Unauthorized — Missing or wrong credentials. Browser will show an auth prompt.
400
Bad Request — Missing or non-numeric input parameters.
405
Method Not Allowed — Use GET.