<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom"><title type="text">Blog posts by Harinarayanan</title><link href="http://world.optimizely.com" /><updated>2023-04-28T18:14:23.0000000Z</updated><id>https://world.optimizely.com/blogs/harinarayanan/</id> <generator uri="http://world.optimizely.com" version="2.0">Optimizely World</generator> <entry><title>Content Delivery / Headless API Implementation </title><link href="https://world.optimizely.com/blogs/harinarayanan/dates/2023/4/content-delivery--headless-api-implementation-/" /><id>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I was new to the Headless (CD) implementation and learned with the help of existing resources and implemented it successfully for our requirement, so thought of sharing the implementation steps, in case anyone looking for step by step Content Delivery API implementation or Headless Implementation.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;Below are the tools/platforms I &#39;ve used for the implementation,&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;CMS 11&amp;nbsp;&lt;/li&gt;
&lt;li&gt;React&amp;nbsp;&lt;/li&gt;
&lt;li&gt;ContentDeliveryApi.Cms 2.21.1&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;strong&gt;Step: 1&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Install the below packages through the NuGet package manager.&lt;/p&gt;
&lt;pre class=&quot;language-markup&quot;&gt;&lt;code&gt;&amp;lt;package id=&quot;EPiServer.ContentDeliveryApi&quot; version=&quot;2.19.0&quot; targetFramework=&quot;net48&quot; /&amp;gt;
  &amp;lt;package id=&quot;EPiServer.ContentDeliveryApi.Cms&quot; version=&quot;2.21.1&quot; targetFramework=&quot;net48&quot; /&amp;gt;
  &amp;lt;package id=&quot;EPiServer.ContentDeliveryApi.Core&quot; version=&quot;2.21.1&quot; targetFramework=&quot;net48&quot; /&amp;gt;
  &amp;lt;package id=&quot;EPiServer.ContentDeliveryApi.Forms&quot; version=&quot;2.21.1&quot; targetFramework=&quot;net48&quot; /&amp;gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Step: 2&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Add the below configs into web.config, I&#39;m not sure 100% knowledge on why this is required but either of those configs should be set to &lt;strong&gt;true,&lt;/strong&gt; and the other one should be set to &lt;strong&gt;false,&lt;/strong&gt; and not both of them set to &lt;strong&gt;true or false&lt;/strong&gt;.&lt;/p&gt;
&lt;pre class=&quot;language-markup&quot;&gt;&lt;code&gt; &amp;lt;add key=&quot;episerver:contentdeliverysearch:maphttpattributeroutes&quot; value=&quot;true&quot; /&amp;gt;
    &amp;lt;add key=&quot;episerver:contentdelivery:maphttpattributeroutes&quot; value=&quot;false&quot; /&amp;gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Step: 3&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Add a new Initialization module,&lt;/p&gt;
&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;using EPiServer.ContentApi.Cms;
using EPiServer.ContentApi.Core.Configuration;
using EPiServer.Framework;
using EPiServer.Framework.Initialization;
using EPiServer.ServiceLocation;
using System;
using System.Linq;

namespace Alloy.Web.Admin.ContentDeliveryApi
{
    [InitializableModule]
    [ModuleDependency(typeof(ContentApiCmsInitialization))]
    public class ContentDeliveryApiInit : IConfigurableModule
    {
        public void ConfigureContainer(ServiceConfigurationContext context)
        {
            context.Services.Configure&amp;lt;ContentApiConfiguration&amp;gt;(config =&amp;gt; {
                config.Default().SetMinimumRoles(String.Empty);
            });
        }

        public void Initialize(InitializationEngine context)
        {
            //Add initialization logic, this method is called once after CMS has been initialized
        }

        public void Uninitialize(InitializationEngine context)
        {
            //Add uninitialization logic
        }
    }
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Once you are done with the above steps you can re-build and run your solution to verify everything okay with the solution.&lt;/p&gt;
&lt;p&gt;If you see your solution is working fine, then you can test Content Delivery API by accessing a site content with the help of &lt;strong&gt;Visual Studio Code&lt;/strong&gt;(I feel it&#39;s a very feasible tool to access Headless content), In case if you don&#39;t have a &lt;strong&gt;REST Client&lt;/strong&gt; in your Visual Studio Code please install the below Extension, It&#39;s really useful during our Headless implementation to test content.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/link/22eaae12d72e4d51afec8c522c10eae7.aspx&quot; /&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;span style=&quot;font-size:&amp;#32;14pt;&quot;&gt;&lt;strong&gt;Examples:&lt;/strong&gt;&lt;/span&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;To get site definitions:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://localhost:44300/api/episerver/v2.0/site/&quot;&gt;https://localhost:44300/api/episerver/v2.0/site/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/link/e59bb74c9d6944b89062e77e5c18614e.aspx&quot; /&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;To get your page content: &lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://localhost:44300/api/episerver/v2.0/content/420003&quot;&gt;https://localhost:44300/api/episerver/v2.0/content/420003&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;To Expand the Content Area/Content reference within Content:&amp;nbsp;&lt;/strong&gt;&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;&lt;a href=&quot;https://localhost:44300/api/episerver/v2.0/content/420003?expand=*&quot;&gt;https://localhost:44300/api/episerver/v2.0/content/420003?expand=*&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;strong&gt;To Get Language-Specific Content:&amp;nbsp;&lt;/strong&gt;&lt;/div&gt;
&lt;div&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;&lt;a href=&quot;https://localhost:44300/api/episerver/v2.0/site/?language=fr&quot;&gt;https://localhost:44300/api/episerver/v2.0/site/?language=fr&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;In this way, your content is ready to access through Content Delivery API.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;strong&gt;Step 4:&lt;/strong&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;If you above all are working as expected we can move on to the next step.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;The next will be creating the Content type, ViewModel, Controller, Basic view, and React development for fetching data and rendering data.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;In my case had to create all of the above from scratch, maybe your case may differ. So I like to cover those parts in another blog.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style=&quot;text-decoration:&amp;#32;underline;&quot;&gt;&lt;em&gt;&lt;strong&gt;Please feel free to add your comments, questions, thoughts, or any missing steps.&lt;/strong&gt;&lt;/em&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style=&quot;text-decoration:&amp;#32;underline;&quot;&gt;&lt;em&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/em&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style=&quot;text-decoration:&amp;#32;underline;&quot;&gt;&lt;em&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/em&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;Thanks for reading. Have a good day.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;</id><updated>2023-04-28T18:14:23.0000000Z</updated><summary type="html">Blog post</summary></entry></feed>