Skip to content

Instantly share code, notes, and snippets.

@adegbengaagoro
Created February 10, 2022 02:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adegbengaagoro/ea773e884bc3a6e9932f4dfd8a771fa1 to your computer and use it in GitHub Desktop.
Save adegbengaagoro/ea773e884bc3a6e9932f4dfd8a771fa1 to your computer and use it in GitHub Desktop.
Content Negotiation - Official AdonisJS Example
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 })
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment