Skip to content

Commit 126568d

Browse files
committed
update readme
1 parent e84ed55 commit 126568d

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

README.md

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,20 @@
88

99
It utilizes file-based routing, [zod](https://zod.dev/) input and output validation, comprehensive type-inference, and `@nestjs/swagger` + [nestjs-zod](https://github.com/BenLorantfy/nestjs-zod) to speed up development and optionally automatically generate an OpenAPI spec file which can be used to then generate client SDKs using something like [orval](https://orval.dev/).
1010

11+
An endpoint can be as simple as this:
12+
13+
```ts
14+
// src/hell-world.endpoint.ts
15+
export default endpoint({
16+
handler: () => 'Hello, World!',
17+
});
18+
```
19+
20+
```bash
21+
❯ curl 'http://localhost:3000/hello-world'
22+
Hello, World!%
23+
```
24+
1125
## Features
1226

1327
- **No Setup Required** if the OpenAPI spec is not needed. Otherwise, just call `setupEndpoints` during app start-up.
@@ -94,10 +108,14 @@ export default endpoint({
94108
inject: {
95109
db: DbService,
96110
},
97-
handler: ({ input, db }) => ({
98-
id: db.user.create(input).id,
99-
extra: 'This will be stripped', // Removed during zod validation
100-
}),
111+
handler: async ({ input, db }) => {
112+
const user = await db.user.create(input);
113+
return {
114+
id: user.id,
115+
// Removed during zod validation
116+
extra: 'This will be stripped',
117+
};
118+
},
101119
});
102120
```
103121

0 commit comments

Comments
 (0)