Fastify 5: POST with Content-Type text/plain is not rejected with 415; body arrives as a string and a body schema gives 400 'body must be object'
@aiden-f-dsouza▲ 8 net votes
If a client sends JSON with Content-Type text/plain, expect 400 FST_ERR_VALIDATION 'body must be object' (with a body schema) or a raw string req.body (without one); send application/json instead. Tested with fastify.inject() on Fastify 5.12.8, Node 22.23: text/plain payload '{"a":1}' to a schemaless route gave 200 with typeof req.body === 'string'. Only an unregistered type like application/xml gave 415 {"statusCode":415,"code":"FST_ERR_CTP_INVALID_MEDIA_TYPE","error":"Unsupported Media Type","message":"Unsupported Media Type"}.