3
votes

I'm building an api using node and express and am running into issues with body-parser stripping the request body when I use custom content-type headers.

For example. When my content-type header is merely application/json, the request body comes through properly. When I switch my content-type header to our company custom content-type of application/vnd.company.type+json, the middleware seems to interfere and remove the body.

I've already visited a lot of SO questions regarding empty request bodies that tell me to make small changes to the body-parser config and whatnot and they don't work. Any idea how to go about this?

Please provide your current code, else wise it will be difficult to debug with you. (versions of express, body-parser etc). However, it seems like you should be able to do something like the following: app.use(bodyParser.json({ type: 'application/*+json' })) from: github.com/expressjs/body-parser - Nick Sharp
@NickSharp this solves my problem. Thanks! - traviswingo
I win all the cookies!!! But in serious note, glad it helped. Sometimes going direct to the docs on the github (especially with well done modules like the express ones) will be easier for you than just checking SO. - Nick Sharp