Skip to content

Instantly share code, notes, and snippets.

@chathurangat
Created February 21, 2018 10:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chathurangat/9adfda03d5c0f0ee4cf90400ec83fc32 to your computer and use it in GitHub Desktop.
Save chathurangat/9adfda03d5c0f0ee4cf90400ec83fc32 to your computer and use it in GitHub Desktop.
import {RequestHandlerService} from "./service/RequestHandlerService";
const express = require('express');
const router = express.Router();
router.all('/*', function (request, response, next) {
console.log(" this will be applied to all routes ");
next();
});
router.get("/", async (request, response)=> {
let message = await RequestHandlerService.handleHttpRequest(request.method, request.path);
response.status(200).json({
"message": message
});
});
router.get("/products", (request, response)=> {
response.status(200).json({
"message": "HTTP " + request.method + " Request with URL Pattern " + request.path
});
});
router.get("/products/:id", (request, response)=> {
response.status(200).json({
"message": "HTTP " + request.method + " Request with URL Pattern " + request.path
});
});
router.post("/products", (request, response)=> {
response.status(200).json({
"message": "HTTP " + request.method + " Request with URL Pattern " + request.path
});
});
module.exports = router;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment