Skip to Content
Static Params

Static Params Example

This example demonstrates a static API  represented by a single handler that renders 6 sets of static parameters: section (a | b) and page (1 | 2 | 3).

Result



Code

src/modules/static/staticParams/StaticParamsController.ts
import { z } from 'zod'; import { prefix, get, operation } from 'vovk'; import { withZod } from 'vovk-zod'; @prefix('static-params') export default class StaticParamsController { @operation({ summary: 'Static Params', description: 'Get the static params: section and page', }) @get('{section}/page{page}.json', { staticParams: [ { section: 'a', page: '1' }, { section: 'a', page: '2' }, { section: 'a', page: '3' }, { section: 'b', page: '1' }, { section: 'b', page: '2' }, { section: 'b', page: '3' }, ], }) static getStaticParams = withZod({ params: z.object({ section: z.enum(['a', 'b']), page: z.enum(['1', '2', '3']), }), handle: async (_req, { section, page }) => { return { section, page }; }, }); }

The code above is fetched from GitHub repository. 

Last updated on