Routing Mapping Specification
Background
FaasJS API route resolution is file-based. This spec standardizes backend route mapping so Zero-Mapping remains explicit: file path and request path stay in one-to-one alignment by default.
Frontend page components may still live under src/pages, but FaasJS does not
auto-discover webpage routes for React applications anymore. Browser routing is
an application concern and is out of scope for this spec.
Related references:
packages/core/src/server/routes.tspackages/core/src/server/routes.test.tsdocuments/projects/faasjs/rfc-spa-api-zero-mapping-v0.1-short.md
Goals
- Keep API locations discoverable from the request path without an extra mapping table.
- Reduce ambiguity for humans and AI coding agents.
- Keep backend route search order predictable.
Non-goals
- Introducing path aliases or rewrite layers.
- Replacing file-system routing with a registry-based router.
- Adding dynamic filename segments such as
[id]or[...slug]in this V1 spec. - Defining browser routing or SPA page discovery behavior.
Normative Rules
1. File naming and placement
- API entry files MUST end with
.api.ts. - API files SHOULD be placed under
api/directories for SPA-style projects. - API files MUST NOT be placed under
components/directories. - Files other than
*.api.tsMUST NOT create API routes implicitly.
2. Zero-mapping routing
- Request path and file path MUST keep direct mapping (Zero-Mapping by default).
- API routes MUST map from the full path under
src/; implementations MUST NOT rely on implicit rewrites such asactions -> api. - Implementations MUST NOT add hidden alias routes that break path/file predictability.
3. API route file search order
Given API request path <p>, route resolution MUST probe in this order:
<p>.api.ts<p>/index.api.ts<p>/default.api.ts- Parent fallback chain:
<parent>/default.api.tsup to root scope
If no candidate exists, the request is treated as not found.
Examples
| File | Route |
|---|---|
src/pages/todo/api/list.api.ts |
POST /pages/todo/api/list |
src/pages/todo/api/index.api.ts |
POST /pages/todo/api |
src/pages/todo/default.api.ts |
fallback for /pages/todo/* |
src/pages/default.api.ts |
fallback for unmatched routes under /pages/* |
API fallback example:
- Request:
POST /pages/todo/item/unknown - Probe order:
src/pages/todo/item/unknown.api.tssrc/pages/todo/item/unknown/index.api.tssrc/pages/todo/item/unknown/default.api.tssrc/pages/todo/item/default.api.tssrc/pages/todo/default.api.tssrc/pages/default.api.ts