srgbnd
srgbnd

Reputation: 5644

Why payload is not parsed automatically?

hapijs 17.2.0

The route is

{
  method: 'POST',
  path: '/node/create',
  handler: function(request, h) {
    console.log(request.payload);
  },  
}

Post my data

curl -d '{"path": "dinos.456", "node": {"name": "velociraptor", "speed": 50, "force": 20}}' -X POST http://localhost:7001/node/create

And I see this result on the server

{ '{"path": "dinos.456", "node": {"name": "velociraptor", "speed": 50, "force": 20}}': '' }

Why is the payload not parsed into object automatically like it was in hapi v16? Maybe I miss some new option in the route?

Upvotes: 0

Views: 357

Answers (1)

quantong zhao
quantong zhao

Reputation: 61

if not set

{
   method: 'POST',
   config: {
      validate: {
          payload: { /* joi schema */  }
      }
   }
}

then the payload will be a row buffer payload, you need to format it by yourself

Upvotes: 1

Related Questions