Skip to content

Instantly share code, notes, and snippets.

@philipodev
Created March 26, 2018 07:51
Show Gist options
  • Save philipodev/5324fdcad063976efdf851f5b163ccd6 to your computer and use it in GitHub Desktop.
Save philipodev/5324fdcad063976efdf851f5b163ccd6 to your computer and use it in GitHub Desktop.
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