Create API routes
Connect a new HTTP endpoint to a model’s SQL-backed CRUD, or generate a custom handler and service.
▶ Watch the demoOn this page
Create POST /members for User
- Press g and select User.
- Choose Create a row (create a row). POST is selected automatically.
- Enter
/members, then accept or change the proposed function name. - Confirm Create files (create files).
- Restart with s, then r, to load the route.
This endpoint uses User’s existing CRUD and SQL queries. It writes to users; it does not create another table.
miblo route add create_member --resource User --action create --path /members --yesAvailable actions
| CLI action | Method | Example path |
|---|---|---|
| list | GET | /members |
| get | GET | /members/{id} |
| create | POST | /members |
| update | PATCH | /members/{id} |
| delete | DELETE | /members/{id} |
Single-row actions require exactly one {id} parameter. List and create accept none. Different methods can share a path with distinct module names.
miblo route add members --resource User --action list --path /members --yes
miblo route add member --resource User --action get --path '/members/{id}' --yesA list action at /users/active still returns a paginated list. Naming a path does not implement a filter or permission rule.
Generate a function to implement
In g, select Custom logic — no model (custom logic without a model), or a model followed by Custom logic — to implement (501). Choose method, path, function name and optional request body.
miblo route add activate_user --method POST --path '/users/{id}/activate' --resource User --json-body --yeshandlers.rs, requests.rs and service.rs are created in src/resources/custom_routes/activate_user/. The route returns 501 until its business function is implemented.
Select the route and press e. The function receives the SQL pool, path parameters, query parameters and optional JSON. Adapt the types, implement the behavior, then restart.
Templates, paths and conflicts
Model actions require template pack 0.6.0. In older projects, use u → GitHub Releases, or miblo template update. Existing models keep their architecture.
Paths use /segments/{parameters}, without query strings or wildcards. Duplicate method/path pairs and known CRUD or /health collisions are rejected. GET reserves HEAD. Check routes registered outside Miblo yourself.
--dry-run previews the plan; --offline uses cached templates.