JSON Parsing
Newgate automatically parses JSON request bodies when the Content-Type header is set to application/json.
Usage
app.post('/data', (req, res) => {
// req.body is already an object
const { name, email } = req.body;
res.json({ received: name });
});
Error Handling
If the JSON is invalid, Newgate will throw a 400 Bad Request error. You can catch this with error middleware if needed, but it's handled automatically by default.
// Example validation manual check
app.post('/strict-json', (req, res) => {
if (req.bodyType !== 'json') {
return res.status(400).send('JSON required');
}
// ...
});
Last updated: 12/11/2025
Edit on GitHub