vex
1.0.0
module main
import nedpals.vex.router
import nedpals.vex.server
import nedpals.vex.ctx
fn print_req_info ( mut req ctx.Req, mut res ctx.Resp) {
println ( ' ${req.method} ${req.path} ' )
}
fn do_stuff ( mut req ctx.Req, mut res ctx.Resp) {
println ( 'incoming request!' )
}
fn main () {
mut app := router. new ()
app. use (do_stuff, print_req_info)
app. route (.get, '/' , fn (req & ctx.Req, mut res ctx.Resp) {
res. send_file ( 'index.html' , 200 )
})
app. route (.get, '/public/*path' , fn (req & ctx.Req, mut res ctx.Resp) {
res. send_file ( 'public/' + req.params[ 'path' ], 200 )
})
app. route (.get, '/path/:name' , fn (req & ctx.Req, mut res ctx.Resp) {
println ( 'path is ${req.params["name"]} ' )
}, fn (req & ctx.Req, mut res ctx.Resp) {
res. send ( 'path: ' + req.params[ 'name' ], 200 )
})
app. route (.get, '/complex/:name/*path' , fn (req & ctx.Req, mut res ctx.Resp) {
res. send ( 'username: ' + req.params[ 'name' ] + ' n path: ' + req.params[ 'path' ], 200 )
})
server. serve (app, 6789 )
}
Wiki를 읽고 VEX를 설정하고 사용하는 방법을 알아보세요.
GET
, POST
, PUT
, PATCH
, DELETE
및 OPTION
HTTP 메소드를 지원합니다. application/x-www-form-urlencoded
지원 application/json
지원 multipart/form-data
지원 git checkout -b my-new-feature
).git commit -am 'Add some feature'
)git push origin my-new-feature
) 예제는 /examples
디렉터리에서 찾을 수 있습니다.
MIT