Skip to content

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.

  • Python 3.11+
  • JustAPI installed (pip install justapi)

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!"}
Terminal window
# Using Python directly
python main.py
# Or with UV (faster startup)
uv run main.py

Expected 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/docs
Terminal window
curl http://127.0.0.1:8000/

Expected response:

{"message":"Hello, World!"}

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:

Terminal window
curl http://127.0.0.1:8000/hello/JustAPI
# Output: {"greeting":"Hello, JustAPI!"}
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:

Terminal window
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}
from justapi import JustAPIApp
from 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")
  • 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)