FastAPI Demo API Guide

🚀 Quick Start

  1. First, get your authentication token:
    curl -X POST https://fastapi-starter-sable.vercel.app/token \
        -d "username=testuser&password=testpass" \
        -H "Content-Type: application/x-www-form-urlencoded"

    This will return a response like:

    {
        "access_token": "user_testuser_1234567890",
        "expires_at": "2024-03-21T10:30:00"
    }
  2. Use the received token in subsequent requests:
    curl -H "Authorization: Bearer user_testuser_1234567890" https://fastapi-starter-sable.vercel.app/items

📊 Demo Data

The API comes pre-populated with sample items:

Test User Credentials:

📌 Public Endpoints

These endpoints are accessible without authentication

GET /api

Check API status

curl https://fastapi-starter-sable.vercel.app/api
GET /public/items

List public items (No auth required)

Parameters:

curl "https://fastapi-starter-sable.vercel.app/public/items?skip=0&limit=2"
GET /public/items/{item_id}

Get specific public item by ID

curl https://fastapi-starter-sable.vercel.app/public/items/1

🔒 Protected Endpoints

These endpoints require authentication

POST /token

Get authentication token (valid for 24 hours)

curl -X POST https://fastapi-starter-sable.vercel.app/token \
    -H "Content-Type: application/x-www-form-urlencoded" \
    -d "username=testuser&password=testpass"
POST /token/revoke

Revoke current token

curl -X POST https://fastapi-starter-sable.vercel.app/token/revoke \
    -H "Authorization: Bearer user_testuser_1234567890"
GET /items?skip=0&limit=2

List items with pagination (Auth required)

Parameters:

curl -H "Authorization: Bearer user_testuser_1234567890" "https://fastapi-starter-sable.vercel.app/items?skip=0&limit=2"
GET /items/1

Get specific item by ID (Auth required)

curl -H "Authorization: Bearer user_testuser_1234567890" https://fastapi-starter-sable.vercel.app/items/1
POST /items

Create new item (Auth required)

curl -X POST https://fastapi-starter-sable.vercel.app/items \
    -H "Authorization: Bearer user_testuser_1234567890" \
    -H "Content-Type: application/json" \
    -d '{
        "name": "New Item",
        "description": "A brand new item",
        "price": 49.99,
        "tags": ["new", "sample"],
        "is_offer": false
    }'
PUT /items/1

Update entire item (Auth required)

curl -X PUT https://fastapi-starter-sable.vercel.app/items/1 \
    -H "Authorization: Bearer user_testuser_1234567890" \
    -H "Content-Type: application/json" \
    -d '{
        "name": "Updated Laptop",
        "description": "Updated high-performance laptop",
        "price": 1099.99,
        "tags": ["electronics", "computers", "updated"],
        "is_offer": true
    }'
PATCH /items/1

Partially update item (Auth required)

curl -X PATCH https://fastapi-starter-sable.vercel.app/items/1 \
    -H "Authorization: Bearer user_testuser_1234567890" \
    -H "Content-Type: application/json" \
    -d '{
        "price": 899.99,
        "is_offer": true
    }'
DELETE /items/1

Delete item (Auth required)

curl -X DELETE -H "Authorization: Bearer user_testuser_1234567890" https://fastapi-starter-sable.vercel.app/items/1

🔑 Authentication

Token Management:

📚 API Documentation

📝 Notes