-
-
Save kasramp/20e369ef57322e1cd88df7de73c0e554 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
router.post("/v1/users", async (context) => { | |
if (!context.request.hasBody) { | |
context.response.status = 400; | |
context.response.body = { error: "Request body cannot be empty" }; | |
} else { | |
const { firstName, lastName, age } = (await context.request.body(true)).value | |
const ageInt = parseInt(age); | |
if (firstName && lastName && ageInt) { | |
dummyUsers.push({ id: dummyUsers.length + 1, firstName: firstName, lastName: lastName, age: ageInt }); | |
context.response.status = 201; | |
context.response.body = dummyUsers[dummyUsers.length - 1]; | |
} else { | |
context.response.status = 400; | |
context.response.body = { error: "Invalid payload's provided" }; | |
} | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment