Oracle Magazine, September/October 2018
Database Developer OPEN SOURCE rate routing logic based on some predefined rules such as the filenames and properties they expose Alternatively you could add a file to the config directory and read that at start time Consider such automation when your API matures and its patterns are well known In this application you will take a slightly lower level approach by defining routes programmatically via a new router module Create a new file named router js in the services directory Add the following code to the file and save your changes const express require express const router new express Router const employees require controllers employees js ORACLE MAGAZINE SEPTEMBER OCTOBER 2018 66 router route employees id get employees get module exports router This router module starts by bringing in Express and then creates a new instance of Express Router class The routers route method is used to define a route based on the route path passed in The path includes a parameter named id which is made optional by the question mark that follows it The route thats returned from route includes methods that correspond to HTTP methods and enable handlers to be defined In this case the get method is used to map an incoming GET request to the get function defined in the employees controller which will be created in the next part of this article
You must have JavaScript enabled to view digital editions.