Keep the change close to the contract
A small feature often starts as an API and later needs a page. The hazard is that the new page starts loading the same entity under a different validation or error policy. A useful boundary is the request lifecycle. Identify the resource at one layer, resolve it through the same service, then format the result at the edge.
VextJS documents JSON and React SSR handlers under the same routes directory. The handlers can call the same named service and then return either JSON or rendered HTML. A routing contract can supply HTTP validation, OpenAPI, and generated client types without copying every schema into a second router.
Run the same service through two handlers
The VextJS 2.1.0 fullstack-react starter with the native adapter registers both routes in defineRoutes. Each calls app.services.example.greeting('Vext') and then chooses a representation with res.render or res.json. To reproduce, set VEXT_PACKAGE to 2.1.0 in the shell that runs npx vextjs@2.1.0 create route-demo --template fullstack-react --adapter native. In the generated project, run npm run build and npm start -- --host 127.0.0.1, then send these requests to the reported loopback port.
| Request | Observed in a local 2.1.0 production fixture |
|---|---|
GET / |
200, HTML containing Hello, Vext! |
GET /api/hello |
200, JSON with data.message equal to Hello, Vext! Welcome to vext. |
GET /unregistered-example/ |
404 for a URL with no registered handler |
For a resource lookup you implement, test a valid ID through both representations and check that HTML and JSON name the same record. Give malformed IDs a validation-error test, and give valid IDs that have no matching record a separate application 404 test.
Snapshot at the presentation boundary
A site can add a separate export step. Start the pinned application locally, request an explicit route inventory, and store the server's HTML and approved assets. The route contract defines valid inputs. The export inventory determines which specific paths become static pages.
Use a direct request to an inventoried page such as /zh/blog/one-route/ in both SSR and a clean static server. Check status 200, Chinese content, the canonical path with its trailing slash, and successful asset requests. Check the slashless URL against the site's redirect policy. Request an uninventoried path such as /zh/blog/unregistered-example/ and require a real 404. Scan the exported files for private preview data before publishing.
A snapshot serves versioned, session-free pages without a live rendering process. Content changes require a fresh build. Authenticated or user-specific reads and live writes still need a server-side policy.