API Academy
🌐 English
  • 🌐 English
  • 🌐 繁體中文
HomePetstore APIExplore more APIs
HomePetstore APIExplore more APIs
🌐 English
  • 🌐 English
  • 🌐 繁體中文
🌐 English
  • 🌐 English
  • 🌐 繁體中文
  1. Developing APIs
  • Introduction
  • Table of Contents
  • API Academy
    • Get Started
      • What is an API?
      • How Does an API Work?
      • How to Call an API?
      • How to Read an API Documentation?
      • Chapter Summary
      • Get realtime weather
    • API Fundamentals
      • API Funtamentals: Overview
      • Method & Path
      • Parameters
      • Request Body
      • Responses
      • API Specification & OAS
      • Chapter Summary
    • Working with APIs
      • Working with APIs: Overview
      • Making Requests from Spec
      • Environments and Variables
      • Chaining Multiple Endpoints
      • Handling Authentication
      • Handling API Signatures
      • Introduction to Scripts
      • Chapter Summary
    • Mocking APIs
      • Mocking APIs: Overview
      • Smart Mock
      • Mock Expectations
      • Cloud Mock
      • Mock Scripts
      • Chapter Summary
    • Designing APIs
      • Designing APIs: Overview
      • Introduction to API Design
      • Creating Your First API Project
      • Analyzing Requirements and Planning Your API
      • Designing Data Models
      • Designing Endpoints
      • Using Components and Reusability
      • Setting Up Authentication
      • API Design Guidelines
      • Chapter Summary
    • Developing APIs
      • Developing APIs: Overview
      • Setup: Install Your AI Coding Assistant
      • Quick Start: From Spec to Running API in 30 Minutes
      • Understanding the Generated Code
      • Testing Your API with Apidog
      • Deployment: Put Your API Online
      • Chapter Summary
    • Testing APIs
      • Testing APIs: Overview
      • Getting Started: Your First Test Scenario
      • Integration Testing and Data Passing
      • Dynamic Values
      • Assertions and Validations
      • Flow Control: If, For, ForEach
      • Data-Driven Testing
      • Performance Testing
      • Test Reports and Analysis
      • CI/CD Integration
      • Scheduled Tasks and Automation
      • Advanced Testing Strategies
      • Chapter Summary
    • API Documentations
      • API Documentations: Overview
      • Publishing Your First API Doc
      • Customizing Documentation Appearance
      • Interactive Features for Consumers
      • Advanced Publishing Settings
      • Managing API Versions
      • Chapter Summary
    • Advanced API Technologies
      • API Technologies: Overview
      • GraphQL
      • gRPC
      • WebSocket
      • Socket.IO
      • Server-Sent Events (SSE)
      • SOAP
      • Chapter Summary
    • API Lifecycle
      • API Lifecycle: Overview
      • Stages of the API Lifecycle
      • API Governance
      • API Security Best Practices
      • Monitoring and Analytics
      • API Versioning Strategies
      • The Future of APIs
      • Chapter Summary
    • API Security
      • API Security: Overview
      • API Security Fundamentals
      • Authentication vs Authorization
      • Understanding OAuth 2.0 and OpenID Connect
      • JSON Web Tokens (JWT)
      • OWASP API Security Top 10
      • Encryption and HTTPS
      • Chapter Summary
    • API Tools
      • API Tools: Overview
      • The Evolution of API Tools
      • API Clients
      • Command Line Tools (cURL, HTTPie)
      • API Design and Documentation Tools
      • API Mocking Tools
      • API Testing Tools
      • All-in-One API Platforms
      • Chapter Summary
    • API Gateway
      • API Gateway: Overview
      • What is an API Gateway?
      • Key Features of API Gateways
      • API Gateway vs Load Balancer vs Service Mesh
      • Popular API Gateway Solutions
      • The BFF (Backend for Frontend) Pattern
      • Chapter Summary
  • Modern Pet Store
    • Pet
      • Get Pet
      • Update Pet
      • Delete Pet
      • Create Pet
      • List Pets
      • Upload Pet Image
    • User
      • Update User
      • Get User
      • Delete User
      • Login
      • Logout
      • Create User
    • Store
      • List Inventory
      • Create Order
      • Get Order
      • Delete Order
      • Callback Example
      • Pay for an Order
    • Payments
      • Pay Order
    • Chat
      • Create Chat Completion
    • Webhooks
      • Pet Adopted Event
      • New Pet Available Event
  • Schemas
    • Pet
    • Category
    • User
    • ApiResponse
    • OrderPayment
    • Tag
    • Order
    • Links-Order
    • PetCollection
    • Bank Card
    • Bank Account
    • Links
    • Error
HomePetstore APIExplore more APIs
HomePetstore APIExplore more APIs
🌐 English
  • 🌐 English
  • 🌐 繁體中文
🌐 English
  • 🌐 English
  • 🌐 繁體中文
  1. Developing APIs

Quick Start: From Spec to Running API in 30 Minutes

This is where it gets real. In the next 30 minutes, you'll go from your API design in Apidog to a fully working API running on your computer. No weeks of learning. No hundreds of lines of manual coding. Just results.
Here's what we're doing:
1.
Export your API design from Apidog (2 minutes)
2.
Use Cursor to generate a complete project (10 minutes)
3.
Run it locally (5 minutes)
Let's go.

Export Your API Specification (2 minutes)#

Your API design in Apidog contains everything the AI needs to generate code. You just need to export it.
Open your User API project in Apidog
Make sure you've completed the "Designing APIs" chapter and have the User module with all six endpoints:
POST /users (register)
POST /user/login
GET /users/{id}
PUT /users/{id}
DELETE /users/{id}
POST /user/logout
Export the OpenAPI specification
1.
Click on your project name in the top left
2.
Go to Settings β†’ Import/Export
3.
Click Export β†’ OpenAPI
4.
Choose OpenAPI 3.0 (not 3.1)
5.
Format: JSON (easier for AI to read)
6.
Click Export
You'll get a file named something like user-api.json. Save it somewhere you can find it easily (like your Desktop).
What you just exported
Open the file in any text editor. You'll see JSON describing your entire API - all your endpoints, request and response schemas, authentication requirements, and data validation rules. This file is the blueprint the AI will use to build your API.

Generate Your Project with Cursor (10 minutes)#

Now comes the magic part. You'll give this specification to Cursor and watch it generate a complete, working project.
Create a project folder
Make a new folder somewhere organized:
Or just create it wherever you keep projects. The location doesn't matter.
Open the folder in Cursor
1.
Launch Cursor
2.
File β†’ Open Folder
3.
Select the folder you just created
Add your API specification
Drag your exported user-api.json file into Cursor's file explorer. It should appear in the sidebar.
Open Cursor Composer
Press Cmd+I (Mac) or Ctrl+I (Windows/Linux). This opens Composer mode, which can generate entire projects.
Use this prompt
Copy this entire prompt and paste it into Composer:
I have an OpenAPI 3.0 specification in user-api.json. Generate a complete, production-ready Python FastAPI project that implements this spec exactly.

TECH STACK:
- FastAPI (web framework)
- SQLAlchemy (ORM)
- SQLite for development (easy PostgreSQL migration later)
- JWT authentication (python-jose)
- Password hashing (passlib with bcrypt)
- Pydantic v2 (validation)
- Uvicorn (ASGI server)

REQUIREMENTS:
1. Implement ALL endpoints from the OpenAPI spec
2. Request/response formats must match the spec exactly
3. All HTTP status codes as specified
4. JWT token generation and validation
5. Password hashing (never store plain text)
6. Proper error handling with meaningful messages
7. Input validation matching the schemas
8. CORS enabled for local development
9. Clear code comments explaining key parts

PROJECT STRUCTURE:
user-api/
β”œβ”€β”€ main.py # App entry point, routes registration
β”œβ”€β”€ database.py # Database connection and session
β”œβ”€β”€ auth.py # JWT token functions
β”œβ”€β”€ dependencies.py # Reusable dependencies (get_db, get_current_user)
β”œβ”€β”€ models/
β”‚ └── user.py # SQLAlchemy database model
β”œβ”€β”€ schemas/
β”‚ └── user.py # Pydantic request/response models
β”œβ”€β”€ routers/
β”‚ └── users.py # All user endpoints
β”œβ”€β”€ requirements.txt # Python dependencies
β”œβ”€β”€ .env.example # Environment variables template
└── README.md # Setup and run instructions

IMPORTANT DETAILS:
- Email must be unique (database constraint)
- Password field is write-only (never return it)
- Protected endpoints require valid JWT in Authorization header
- User can only modify/delete their own account
- Tokens expire after 24 hours
- createdAt and updatedAt timestamps auto-managed
- All string inputs trimmed
- Proper HTTP status codes (200, 201, 204, 400, 401, 403, 404, 422)

Generate all files with complete, working code. Make sure it can run immediately after pip install.
Press Enter and watch Cursor generate your project. This takes about 1-2 minutes. You'll see it create files one by one: main.py, database.py, auth.py, and everything else.
Review what was generated
When it's done, you should have 8-10 files. Click through them in Cursor's sidebar. You don't need to understand everything yet, but notice it's a lot of working code you didn't have to write manually. The code has comments, proper structure, and matches your API specification.
If something looks wrong or files are missing, you can ask Cursor to fix it: "You forgot to create .env.example, please add it"

Run Your API Locally (5 minutes)#

Let's get this thing running.
Open the terminal in Cursor
Press Ctrl+` (backtick key, usually above Tab). This opens a terminal at the bottom of Cursor.
Create and activate a virtual environment
This keeps your project dependencies isolated:
You should see (venv) appear at the start of your terminal prompt.
Install dependencies
This installs FastAPI, SQLAlchemy, and everything else your API needs. Takes about 30-60 seconds.
Run the API
or
You should see output like:
INFO:     Uvicorn running on http://127.0.0.1:8000
INFO:     Application startup complete.
Your API is now running!
Quick verification
Open your browser and go to:
http://localhost:8000/docs
You should see FastAPI's automatic documentation (Swagger UI) showing all your endpoints. If you see this page with your six endpoints listed, everything is working perfectly.

What You Just Did#

In about 15 minutes, you:
βœ… Exported your API design from Apidog as an OpenAPI specification
βœ… Used AI to generate a complete FastAPI project with database, authentication, and validation
βœ… Got it running locally without errors
βœ… Saw your API's interactive documentation
The API you just generated includes:
Six fully implemented endpoints
JWT authentication
Password hashing with bcrypt
SQLite database with SQLAlchemy ORM
Input validation with Pydantic
Proper error handling
CORS support for development
All of this matches your OpenAPI specification exactly. And you didn't write a single line of code manually.

Quick Troubleshooting#

"Module not found" error
Make sure you activated the virtual environment
Run pip install -r requirements.txt again
"Port 8000 already in use"
Something else is using port 8000
Run on a different port: uvicorn main:app --reload --port 8001
Cursor didn't generate all files
Ask it: "Please review the project structure and create any missing files"

What's Next#

You have a working API running on your computer. But before we test it properly in Apidog, let's understand what this code actually does.
In the next chapter, we'll walk through the generated files and explain how everything fits together. You'll learn how the routing works, how authentication is implemented, how the database is structured, and how requests flow through your API.
Continue with β†’ Understanding the Generated Code
Modified atΒ 2025-12-29 10:42:25
Previous
Setup: Install Your AI Coding Assistant
Next
Understanding the Generated Code
Built with