Reputation: 11
can help me how to send POST request in POSTMAN for following array of objects and validate with Joi in hapi server?
var payload = [{ name: 'TEST Name 1',
answer: 'TEST Answer 1',
category: 'food',
score: 10,
question_id: '10001',
created_at: '2016-07-10T20:11:34+00:00' },
{ name: 'TEST Name 1',
answer: 'TEST Answer 1',
category: 'food',
score: 10,
question_id: '10001',
created_at: '2016-07-10T20:11:34+00:00' }];
Below is sample Joi validate in hapi-server.
validate: {
payload: {
answers: {
arraySchema: Joi.array().items(Joi.object().keys({
name: Joi.string(),
answer: Joi.string(),
category: Joi.string(),
score: Joi.number().integer(),
question_id: Joi.string(),
created_at: Joi.date()
}))
}
}
}
Upvotes: 0
Views: 1554
Reputation: 2204
In the Body of your post request, instead of using form-data
, you can use raw
. Just JSON.stringify()
that array of objects you have and throw it in the raw section and you should be set.
Upvotes: 2