Created
February 10, 2022 01:40
-
-
Save adegbengaagoro/901147da88ae5d03c363e074e5dacafc to your computer and use it in GitHub Desktop.
Content Negotiation Example - Implementation with Functions
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
import Route from '@ioc:Adonis/Core/Route' | |
import payloadGeneratorForViewAndApi from 'App/Helpers/payloadGeneratorForViewAndApi' | |
import viewAndApiOutputHelper from 'App/Helpers/viewAndApiOutputHelper' | |
Route.get('posts', async ({ request }) => { | |
const posts = [ | |
{ | |
title: 'Adonis 101', | |
}, | |
{ | |
title: 'Adonis 201', | |
} | |
] | |
const outputType = request.accepts(['html', 'json']) | |
const { viewDataPayload, apiDataPayload } = payloadGeneratorForViewAndApi(posts, 'posts/index', 'All Posts Listed Successfully') | |
return viewAndApiOutputHelper(outputType, viewDataPayload, apiDataPayload) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment