Last active
December 14, 2017 22:14
-
-
Save rawrmaan/fe52e044c4e7f066f23e53088d1c3374 to your computer and use it in GitHub Desktop.
RESTyped route defintion
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 RestypedRouter from 'restyped-express-async' | |
import {MyAPI} from './MyAPI' // <- Your API's RESTyped defintion | |
import * as express from 'express' | |
const app = express() | |
const router = RestypedRouter<MyAPI>(app) | |
// TS compile error if you declare a route that doesn't exist in your API defintion | |
router.post('/login', async req => { | |
// Error if you try to access non-existent body properties | |
const {username, password, twoFactorPin} = req.body | |
// ^ string ^ string ^ number | |
const accessToken = await User.login(username, password, twoFactorPin) | |
// Error if you don't return the specified response type | |
return accessToken | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment