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

StaticParamsController.ts
StaticParamsExample.tsx
1import { z } from 'zod/v4';
2import { prefix, get, operation } from 'vovk';
3import { withZod } from 'vovk-zod';
4
5@prefix('static-params')
6export default class StaticParamsController {
7 @operation({
8 summary: 'Static Params',
9 description: 'Get the static params: section and page',
10 })
11 @get('{section}/page{page}.json', {
12 staticParams: [
13 { section: 'a', page: '1' },
14 { section: 'a', page: '2' },
15 { section: 'a', page: '3' },
16 { section: 'b', page: '1' },
17 { section: 'b', page: '2' },
18 { section: 'b', page: '3' },
19 ],
20 })
21 static getStaticParams = withZod({
22 params: z.object({
23 section: z.enum(['a', 'b']),
24 page: z.enum(['1', '2', '3']),
25 }),
26 handle: async (_req, { section, page }) => {
27 return { section, page };
28 },
29 });
30}
1import { z } from 'zod/v4';
2import { prefix, get, operation } from 'vovk';
3import { withZod } from 'vovk-zod';
4
5@prefix('static-params')
6export default class StaticParamsController {
7 @operation({
8 summary: 'Static Params',
9 description: 'Get the static params: section and page',
10 })
11 @get('{section}/page{page}.json', {
12 staticParams: [
13 { section: 'a', page: '1' },
14 { section: 'a', page: '2' },
15 { section: 'a', page: '3' },
16 { section: 'b', page: '1' },
17 { section: 'b', page: '2' },
18 { section: 'b', page: '3' },
19 ],
20 })
21 static getStaticParams = withZod({
22 params: z.object({
23 section: z.enum(['a', 'b']),
24 page: z.enum(['1', '2', '3']),
25 }),
26 handle: async (_req, { section, page }) => {
27 return { section, page };
28 },
29 });
30}
Last updated on