Created
February 10, 2022 02:07
-
-
Save adegbengaagoro/ea773e884bc3a6e9932f4dfd8a771fa1 to your computer and use it in GitHub Desktop.
Content Negotiation - Official AdonisJS Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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