-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttp_server.v
More file actions
40 lines (32 loc) · 750 Bytes
/
http_server.v
File metadata and controls
40 lines (32 loc) · 750 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
35
36
37
38
39
40
module main
import vweb
fn main() {
vweb.run(&App{}, 8080)
}
struct App {
vweb.Context
}
// http://localhost:8080
fn (mut app App) index() vweb.Result {
return app.html('<h1>Index</h1>')
}
// http://localhost:8080/hello
['/hello']
fn (mut app App) world() vweb.Result {
return app.text('Hello, World!')
}
// http://localhost:8080/hello/world
['/hello/:user']
fn (mut app App) hello_user(user string) vweb.Result {
return app.text('Hello, $user!')
}
// POST http://localhost:8080/post_request
[post]
fn (mut app App) post_request() vweb.Result {
return app.text('POST request!')
}
// POST http://localhost:8080/post/name
['/post/:name'; post]
fn (mut app App) post_with_name(name string) vweb.Result {
return app.text('POST, $name!')
}