-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimple.ts
More file actions
34 lines (29 loc) · 889 Bytes
/
simple.ts
File metadata and controls
34 lines (29 loc) · 889 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/**
* Simple Example - Minimal Setup
*
* This is the absolute minimum code needed to get started.
* Perfect for quick prototyping and understanding the basics.
*
* Run with: npx tsx examples/simple.ts
*/
import { APIServer, z } from '../src/index'
const app = new APIServer()
app.createEndpoint({
method: 'GET',
url: '/hello',
query: z.object({
name: z.string().optional().describe('Name to greet (optional, defaults to "World")'),
}),
response: z.object({
message: z.string().describe('Personalized greeting message'),
}),
handler: async (request) => {
return { message: `Hello, ${request.query.name || 'World'}!` }
},
})
;(async () => {
await app.start()
console.log('\n✅ Simple server is running!')
console.log('📝 Visit http://localhost:3000/docs for Swagger documentation')
console.log('\n💡 Try: curl http://localhost:3000/hello?name=Alice')
})()