Beta version of JEC API
Project description
JEC-API
Features
- Class-Based Routes: Group related endpoints into a single class.
- Strict Method Mapping: Methods named
get,post,put,delete,patch,options, orheadare automatically mapped to their respective HTTP verbs. - Data Object Support: Built-in support for Pydantic models. Type hints are automatically used for request body validation and response model registry.
- FastAPI Native: Fully compatible with FastAPI dependencies and OpenAPI generation.
Installation
pip install jec-api
Quick Start
- Define a Route Class
# routes.py
from pydantic import BaseModel
from jec_api import Route
class UserResponse(BaseModel):
id: int
name: str
class CreateUser(BaseModel):
name: str
class Users(Route):
# Strictly mapped to GET /users
async def get(self) -> list[UserResponse]:
"""List all users"""
return [UserResponse(id=1, name="Alice")]
# Strictly mapped to POST /users
async def post(self, data: CreateUser) -> UserResponse:
"""Create a user"""
return UserResponse(id=2, name=data.name)
class UserDetail(Route):
# Custom path with parameter
path = "/users/{user_id}"
async def get(self, user_id: int) -> UserResponse:
"""Get user by ID"""
return UserResponse(id=user_id, name="Alice")
- Create the App
# main.py
from jec_api import Core
core = Core(title="My API")
# Auto-discover routes from a module/package
core.discover("routes")
# Or register manually
from routes import Users
core.register(Users)
- Run it
uvicorn main:core --reload
Usage Guide
Defining Routes
Inherit from jec_api.Route to create a route group. The class name is automatically converted to kebab-case to form the base path (e.g., UserProfiles -> /user-profiles), unless you override it with the path attribute.
Method Mapping
JEC-API maps methods to HTTP verbs based on their exact names:
| Method Name | HTTP Verb | Path |
|---|---|---|
get() |
GET | / |
post() |
POST | / |
put() |
PUT | / |
delete() |
DELETE | / |
patch() |
PATCH | / |
options() |
OPTIONS | / |
head() |
HEAD | / |
Note: Methods with other names (e.g.,
get_users,helper_method) are ignored and will not be registered as API endpoints.
Path Parameters
To define routes with path parameters, override the path attribute on the Route class.
class Users(Route):
path = "/users/{id}"
async def get(self, id: int):
return {"id": id}
Data Validation and Objects
JEC-API leverages Pydantic for data validation and schema generation.
- Request Body: The type hint of the first non-
selfparameter is used as the request body. - Response Model: The return type hint is used as the
response_modelfor the OpenAPI schema and serialization.
class Users(Route):
async def post(self, data: UserSchema) -> UserResponse:
# data is automatically validated and parsed
return UserResponse(...)
Manual Registration
You can register routes manually if you prefer not to use auto-discovery:
from my_routes import MyRoute
app.register(MyRoute, tags=["Custom Tag"])
Auto-Discovery
The discover() method recursively searches the specified package for any classes inheriting from Route and registers them.
app.discover("src.routes")
License
MIT License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file jec_api-0.0.4.tar.gz.
File metadata
- Download URL: jec_api-0.0.4.tar.gz
- Upload date:
- Size: 17.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a6146373a527e14b9f2dd57f960802706c9656402d1a5f308be66d75fcc4154f
|
|
| MD5 |
5f1f067a04cd70896931c3487bf28a68
|
|
| BLAKE2b-256 |
4268272ba36b802e51781de7a9013275ccea4e79b3729b2bfbd36ca09552c3df
|
File details
Details for the file jec_api-0.0.4-py3-none-any.whl.
File metadata
- Download URL: jec_api-0.0.4-py3-none-any.whl
- Upload date:
- Size: 11.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
250cd36d8c6fad1c92179eb9ab4b081a9a9ed49696b5b30ff4205daa2bf522be
|
|
| MD5 |
fb4ad608f7ce379c3e2fa24724290aae
|
|
| BLAKE2b-256 |
ec388d3f4a5b38d7dc7a3fa23f0b1536bd65e1afd696ab1af5f18ce4edf77b5d
|