Skip to content

Accept header not working #3483

Discussion options

You must be logged in to vote

Hey @feniljariwala82! 👋🏻

First of all, the correct type should be application/json.
Secondly, you must handle that yourself using Content Negotiation.

Route.get('posts', async ({ request, view }) => {
  const posts = [
    {
      title: 'Adonis 101',
    },
  ]

  switch (request.accepts(['html', 'json'])) {
    case 'html':
      return view.render('posts/index', { posts })
    case 'json':
      return posts
    default:
      return view.render('posts/index', { posts })
  }
})

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@feniljariwala82
Comment options

Answer selected by feniljariwala82
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants