NodeJS : Validating request type (checking for JSON or HTML)

前端 未结 4 1509
耶瑟儿~
耶瑟儿~ 2020-12-16 13:32

I would like to check if the type that is requested by my client is JSON or HTML, as I want my route to satisfy both human and machine needs.

I have read the Express

4条回答
  •  隐瞒了意图╮
    2020-12-16 14:14

    It's a bit later, but I found this a better solution for me:

    req.accepts('html, json') === 'json'
    

    Hope it helps!

提交回复
热议问题