Hello World in 2 Minutes
This tutorial walks through creating a complete JustAPI application, step by step. By the end, you’ll have a running API server with multiple endpoints.
Prerequisites
Section titled “Prerequisites”- Python 3.11+
- JustAPI installed (
pip install justapi)
1. Create the App
Section titled “1. Create the App”Create a file named main.py:
from justapi import JustAPIApp
app = JustAPIApp(title="Hello World", version="0.1.0")
@app.get("/")def root(request): return {"message": "Hello, World!"}2. Run It
Section titled “2. Run It”# Using Python directlypython main.py
# Or with UV (faster startup)uv run main.pyExpected output:
[Rust Tokio Runtime] Initialized with 12 worker threads[Rust Tokio Runtime] Listening on http://127.0.0.1:8000[Rust Tokio Runtime] OpenAPI docs at http://127.0.0.1:8000/docs3. Test It
Section titled “3. Test It”curl http://127.0.0.1:8000/Expected response:
{"message":"Hello, World!"}4. Add More Endpoints
Section titled “4. Add More Endpoints”Extend your main.py with a parameterized route:
@app.get("/hello/{name}")def hello_name(request, name: str): return {"greeting": f"Hello, {name}!"}Test it:
curl http://127.0.0.1:8000/hello/JustAPI# Output: {"greeting":"Hello, JustAPI!"}5. Add a POST Endpoint
Section titled “5. Add a POST Endpoint”from pydantic import BaseModel
class Message(BaseModel): content: str author: str
@app.post("/messages/")def create_message(request, msg: Message): return { "received": msg.content, "from": msg.author, "length": len(msg.content), }Test with curl:
curl -X POST http://127.0.0.1:8000/messages/ \ -H "Content-Type: application/json" \ -d '{"content": "Hello from JustAPI!", "author": "Alice"}'Expected response:
{"received":"Hello from JustAPI!","from":"Alice","length":20}Complete Application
Section titled “Complete Application”from justapi import JustAPIAppfrom pydantic import BaseModel
app = JustAPIApp(title="Hello World", version="0.1.0")
class Message(BaseModel): content: str author: str
@app.get("/")def root(request): return {"message": "Hello, World!"}
@app.get("/hello/{name}")def hello_name(request, name: str): return {"greeting": f"Hello, {name}!"}
@app.post("/messages/")def create_message(request, msg: Message): return { "received": msg.content, "from": msg.author, "length": len(msg.content), }
if __name__ == "__main__": app.run("127.0.0.1:8000")Key Concepts
Section titled “Key Concepts”JustAPIApp()— Creates your application and initializes the Rust runtime@app.get()/@app.post()— Route decorators that register handlers in the radix-trie router- Path parameters —
{name}in the path becomes a function parameter - Pydantic models — Auto-validated request bodies with zero-copy parsing
app.run()— Starts the built-in Rust HTTP server (no uvicorn needed)
Next Steps
Section titled “Next Steps”- Path & Query Parameters — URL parameters, query strings, type validation
- Request Body & Validation — Deep dive into schema validation
- Dependency Injection — Reusable components with Depends