Hi Everyone,
I want to export my conent fragment data in JSON format using specfic end point with servlet, I want the ouput of the data like below attached screenshot, Kindly Help me if you have any ideas for this issue.
Thanks.
Solved! Go to Solution.
@Nandheswara Please check this below example for the servlet to return JSON.You need to write the logic to get the content fragment into the json
https://gist.github.com/nateyolles/d4ca683078efd60aa8ac
hello @Nandheswara
There are multiple options to export Content Fragments as json
Option-1:
OOTB Content Services would allow to access Content Fragment data by appending .model.json to the CF. Reference: https://experienceleague.adobe.com/docs/experience-manager-65/developing/components/json-exporter.ht...
It essentially works with Content Fragment component. Example: Add CF to a page via Content Fragment component. Then access its data as http://localhost:4502/content/experience-fragments/wknd/language-masters/en/contributors/stacey-rosw...
Option-2: You should try exploring GraphQL to get Json output from Content Fragments. They are pretty powerful.
I want to export data using servlet so if there any blog means give please
@Nandheswara Please check this below example for the servlet to return JSON.You need to write the logic to get the content fragment into the json
https://gist.github.com/nateyolles/d4ca683078efd60aa8ac
The preferred way to expose the Content Fragment data is through GraphQL, some of the advantages are:
Efficient Data Fetching: GraphQL allows clients to specify the exact data they need, eliminating over-fetching and under-fetching issues commonly found in traditional RESTful APIs.
Flexible and Customizable Queries: With GraphQL, clients have the flexibility to define their own queries to fetch the required data. They can specify the fields, relationships, and fragments they need, enabling them to fetch multiple content fragments in a single request.
Strong Typing and Schema Validation: GraphQL has a strongly typed schema, which acts as a contract between the client and server. This schema allows clients to understand the available data and its structure. Additionally, GraphQL provides schema validation, enabling early detection of errors and providing a clear contract for API consumers.
Reduced Overhead for Backend Development: Developers can add or modify fields within the schema without impacting existing clients, making it easier to evolve the API over time.
Frontend Agnostic: GraphQL decouples the backend from the frontend, allowing clients to choose their preferred programming language or framework.
Why would be the reason to avoid GraphQL and use a servlet instead?