How to Use the API – Base URL and Data Format
Once the application is running, all requests target a single base URL, and both requests and responses use JSON. This section explains how to construct URLs, configure the Postman collection, and format payloads.
Base URL 🌐
All endpoints live under a common base address.
- Default local address
By default, the Flask app listens on port 5000.
Base URL:
http://localhost:5000
(configured in app.run(port=5000, debug=True))
- Postman collection variable
The provided Postman collection uses a {{url}} variable.
- Update
{{url}}once to switch environments. - Example request entry in
Python Rest API.postman_collection.json:
"url": {
"raw": "{{url}}/books",
"host": ["{{url}}"],
"path": ["books"]
}
{
"title": "Postman Tip",
"content": "Use the {{url}} variable to switch hosts and ports in one place."
}
Data Format 📄
Every endpoint expects JSON input and returns JSON output.
Request Payload
- Content-Type:
application/json - Structure: Depends on endpoint (see individual endpoint docs).
- Example – Creating a user:
curl -X POST {{url}}/register \
-H "Content-Type: application/json" \
-d '{
"username": "alice",
"password": "secret123"
}'
Response Payload
- Content-Type:
application/json - Standard envelope: Objects or error messages.
- Example – Successful registration:
{
"message": "User created successfully."
}
Common Headers
| Header | Value | Required | Description |
|---|---|---|---|
| Authorization | JWT <token> |
Yes* | JWT obtained via /auth |
| Content-Type | application/json |
Yes | Indicates JSON request payload |
* Only protected endpoints require the Authorization header.
With the http://localhost:5000 base URL and JSON formatting rules in place, you can seamlessly test and consume all CRUD and authentication endpoints of the library API.