bAILEY
bAILEY2w ago

Basic CRUD API

Hi all, I'm trying to move from Node/Express and so I'm trying to use Deno/Oak for this, as I've heard Oak is pretty good. It's not going so well, I'm trying to create a basic post request for a user account creation but I'm struggling to find documentation on how to do this.
router.post("/register", async (ctx) => {

const body = await ctx.request.body({type: 'json'}).value()
const value = await body.value
console.log(value)

// const username = user.value.get('username')
// console.log(user.get('username'))
})
router.post("/register", async (ctx) => {

const body = await ctx.request.body({type: 'json'}).value()
const value = await body.value
console.log(value)

// const username = user.value.get('username')
// console.log(user.get('username'))
})
This is some of the stuff I've tried so far but I keep getting different errors such as ctx.request.body is not a function, [uncaught application error]: BadRequestError - Unexpected end of JSON input etc Any help and/or pointers to correct documention would be really helpful, thanks! :D
4 Replies
bAILEY
bAILEY2w ago
I'm just trying to access the request body currently ^^
bAILEY
bAILEY2w ago
For example, in the docs, this is all I can find on Router.post and this doesn't help
No description
imPaul
imPaul2w ago
router.post("/register", async (ctx) => {

const body = ctx.request.body({type: 'json'})
const value = await body.value
console.log(value)

// const username = user.value.get('username')
// console.log(user.get('username'))
})
router.post("/register", async (ctx) => {

const body = ctx.request.body({type: 'json'})
const value = await body.value
console.log(value)

// const username = user.value.get('username')
// console.log(user.get('username'))
})
I think you don't have to await the request's body.
bAILEY
bAILEY7d ago
Thanks! :D