Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

134
Vistas
Express Body Parser with Custom Header

I am in the middle of setting up a REST API that takes requests with a custom Content-Type, but I am having trouble parsing the body with the NPM package body-parser. I am running some tests with Mocha and Chai-HTTP and seding my request tests like this:

chai.request(server)
.post('/demo')
.set('Content-Type', 'application/vnd+companyName.v01+json')
.send({name: 'test'})
.end(function(err, res) {/* tests are here */});

In my express app's app.js, I am calling this middleware:

app.use(bodyParser.json({type: 'application/*+json'}));

When I make the type more general, like making it 'application/*', I can pass the request through with a 'application/json' Content-Type, but not my custom one. When I do this, my req.body is an empty object. If bodyParser was just completely not working, req.body would be undefined and not an empty object. By looking at the docs, I feel like my options on my bodyParser call are correct, but clearly not - any insight?

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

vnd+companyName.v01+json isn't a valid media type.

A valid media type should look like:

[ tree. ] subtype name [ +suffix ] [ ; parameters ]

The subtype name can't contain . or + characters, those are reserved for the (optional) tree and suffix, respectively (RFC6838).

So in your case, the mime type should look like this:

application/vnd.companyName-v01+json

However, it seems that there's an additional requirement imposed by body-parser (or rather, type-is, which is used to match content type), in that the subtype name needs to be lower case:

application/vnd.companyname-v01+json

Strangely, that requirement only applies for the body-parser configuration part, the client is allowed to use upper case in its requests.

about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda