Deviopath › Node.js

Is It a JSON Request?

Easy · Headers

Node gives you request headers in req.headers with lower-case names, for example req.headers["content-type"]. The value can carry parameters after a ;, like "application/json; charset=utf-8".

Write a function isJsonRequest(headers) that returns true when the media type (the part before ;) is application/json, ignoring case and surrounding spaces. Return false when the header is missing.

Next: Dependency Type