Created
December 31, 2019 01:17
-
-
Save treyhuffine/82b9ebe67facac026a999a222d030637 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 { Request, Response } from 'express'; | |
interface HelloResponse { | |
hello: string; | |
} | |
type HelloBuilder = (name: string) => HelloResponse; | |
const helloBuilder: HelloBuilder = name => ({ hello: name }); | |
export const rootHandler = (_req: Request, res: Response) => { | |
return res.send('API is working 🤓'); | |
}; | |
export const helloHandler = (req: Request, res: Response) => { | |
const { params } = req; | |
const { name = 'World' } = params; | |
const response = helloBuilder(name); | |
return res.json(response); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment