Oracle Magazine, September/October 2018
Database Developer OPEN SOURCE At this point you have a router but its not currently used in the application To use it open the services web server js file and remove the line at the top that requires the database module it was used only for testing in the previous article Add the following line of code in its place line that requires config web server js is here const router require router js Next replace the entire app get handler that responds to GET requests using the database module all seven lines with the following code ORACLE MAGAZINE SEPTEMBER OCTOBER 2018 67 line that adds morgan to app here Mount the router at api so all routes start with api app use api router Now the router is required in the web service module and mounted at api This means that the full URL for the employees endpoint will be http server port api employees id ADDING CONTROLLER LOGIC The controller logic will take over from the point that the URL endpoint and the HTTP method are known Because the web server is built with Express the controller logic will be defined with custom middleware or functions that have access to the request and response objects as well as the next function
You must have JavaScript enabled to view digital editions.