Routing System
JEC uses a class-based routing system that intuitively maps Python methods to HTTP endpoints.
The Route Class
Every route in your application must inherit from `Route`. This base class handles the magic of converting your methods into FastAPI endpoints.
from jec_api import Route
class MyRoute(Route):
...Defining Endpoints
Define endpoints by naming your class methods after HTTP verbs (`get`, `post`, `put`, `delete`, `patch`).
routes/items.py
class Items(Route):
# GET /items
async def get(self):
return {"items": []}
# POST /items
async def post(self, item: dict):
return {"created": item}
# DELETE /items
async def delete(self):
return {"deleted": True}Important: Only exact method names are mapped. Methods like `get_items` or `post_v2` are ignored and treated as internal helpers.
Path Configuration
Automatic Path Generation
By default, the path is derived from the class name using kebab-case.
UserProfiles→/user-profilesAPIStatus→/api-statusHome→/home
Custom Paths
Override the path by setting the path class attribute.
class UserProfile(Route):
path = "/users/me/profile" # Custom path
async def get(self):
...Request & Response Types
JEC uses Pydantic models for robust validation and serialization.