Search code examples
hapi.jshapi

Hapijs content-type has application/jwt giving 415 unsupported media type


Hi I am using hapijs version 17 for REST API development, when we are using Content-Type as application/jwt, we are getting 415 http error code Unsupported Media Type .. details below ..

Could someone recommend how to set the Content-type header to application/jwt?

server.route({
            method: 'POST',
            path: '/hello',
            config: {
                payload: {
                  allow: 'application/jwt'
                }
              },
            handler: (request, h) => {
                console.log("req------------->",request)
                return "hello";
            }
        });

we get the following error in response:

{
    "statusCode": 415,
    "error": "Unsupported Media Type",
    "message": "Unsupported Media Type"
}

Solution

  • You need to set parse: false to use these content types. Something like this

    payload: {
                  "parse": false,
                  allow: 'application/jwt'
                }