You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+2-32Lines changed: 2 additions & 32 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -122,39 +122,9 @@ return { data: 'value' };
122
122
123
123
## Advanced Usage
124
124
125
-
### Metadata
125
+
### Static Parameters with Metadata
126
126
127
-
You can add metadata to your route handler with the `defineMetadata` method. Metadata is optional and can be used to add additional information to your route handler.
128
-
129
-
```ts
130
-
const metadataSchema =z.object({
131
-
permission: z.string(),
132
-
role: z.enum(['admin', 'user']),
133
-
});
134
-
135
-
exportconst GET =createZodRoute()
136
-
.defineMetadata(metadataSchema)
137
-
.handler((request, context) => {
138
-
// Access metadata from context.metadata
139
-
const { permission, role } =context.metadata!;
140
-
141
-
returnResponse.json({ permission, role });
142
-
});
143
-
```
144
-
145
-
When calling the route, you can pass metadata as part of the context:
146
-
147
-
```ts
148
-
// In your Next.js page/component
149
-
const response =awaitGET(request, {
150
-
params: Promise.resolve({}),
151
-
metadata: { permission: 'read', role: 'admin' },
152
-
});
153
-
```
154
-
155
-
Metadata is optional by default. If you define a metadata schema but don't provide metadata in the context, the handler will still work. If you provide metadata, it will be validated against the schema.
156
-
157
-
### Permission Checking with Metadata
127
+
Metadata enable you to add **static parameters** to the route, for example to give permissions list to our application.
158
128
159
129
One powerful use case for metadata is defining required permissions for routes and checking them in middleware. This allows you to:
0 commit comments