November 2018
Intermediate to advanced
404 pages
10h 16m
English
In the Vapor framework, you can create a struct for API Routes that implements the RouteCollection protocol:
struct ApiRoutes : RouteCollection { func boot(router: Router) throws { let apiRouter = router.grouped("/api") //... }//...}
In the boot(route:) function, set up a router that starts with the top-level /api URI and append each route corresponding to each of your HTTP methods to the boot(route:) function:
// public routeslet publicRouter = apiRouter.grouped("/journal")publicRouter.get("", use: getAll)// admin routeslet adminRouter = apiRouter.grouped("/admin")adminRouter.post(use: newEntry)adminRouter.get(Int.parameter, use: getEntry)adminRouter.put(Int.parameter, use: editEntry)adminRouter.delete(Int.parameter, ...Read now
Unlock full access