Created
March 26, 2018 07:51
-
-
Save philipodev/5324fdcad063976efdf851f5b163ccd6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Controller, Route } from 'hot-controller'; | |
@Controller('/api') | |
export default class HomeController { | |
@Route.GET('/') // matches /api | |
index(req, res) { | |
res.send('Welcome'); | |
} | |
@Route.GET('/about') | |
users(req, res) { | |
res.redirect('/somewhere-else'); | |
} | |
@Route.GET('/users/:id') // matches /api/users/:id | |
async user(req, res) { | |
// this is a async method | |
const user = await getUserById(req.params.id); // get the user data | |
// send it as json | |
res.json({ | |
user | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment