Create API routes

Connect a new HTTP endpoint to a model’s SQL-backed CRUD, or generate a custom handler and service.

▶ Watch the demo
On this page

Create POST /members for User

  1. Press g and select User.
  2. Choose Create a row (create a row). POST is selected automatically.
  3. Enter /members, then accept or change the proposed function name.
  4. Confirm Create files (create files).
  5. 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.

shell
miblo route add create_member --resource User --action create --path /members --yes

Available actions

CLI actionMethodExample path
listGET/members
getGET/members/{id}
createPOST/members
updatePATCH/members/{id}
deleteDELETE/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.

shell
miblo route add members --resource User --action list --path /members --yes
miblo route add member --resource User --action get --path '/members/{id}' --yes

A 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.

shell
miblo route add activate_user --method POST --path '/users/{id}/activate' --resource User --json-body --yes

handlers.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.

Search for a feature or command.

↑ ↓ browse Enter to open