欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

vapor route

程序员文章站 2022-06-02 18:52:00
...

Register 路由注册

    let router = EngineRouter.default()
    try routes(router)
    services.register(router, as: Router.self)

Parameter

/users/:user_id

    // Create a route for /users/:user_id
let user = Route(path: [.constant("users"), .parameter("user_id")], output: ...)

// Create a router and register our route
let router = TrieRouter(...)
router.register(route: user)

// Create empty Parameters to hold dynamic values
var params = Parameters()

// Route the path /users/42
_ = router.route(path: ["users", "42"], parameters: &params)

// The params contains our dynamic value!
print(params) // ["user_id": "42"]