Loading...
Area: Optimizely Content Delivery API
Applies to versions: 2.9.0 and higher

Frequently Asked Questions

Recommended reading 

How do I post to the Content Delivery API?

The Content Delivery API does not currently support POST or PUT of content. If you need your users to save information, you may need to create your own API and storage repository.

How should I use custom routing?

Make sure that your custom routing and and Content Delivery API's custom routing do not conflict with each other.

This can disrupt other partial routers in the site because the request URL is rewritten. To solve this problem, follow these steps:

  • Create a new class (for example, CustomContentApiRouteService) that inherits ContentApiRouteService and then, register a transient lifecycled implementation for a ContentApiRouteService in the initialization service.

  • Override the function ShouldRouteRequest to prevent the URL from being re-written in unexpected cases. For example, requests whose accept types contain application/json are currently handled by our partial router (accept type application/json is a common header). So, you can add one more header (for example, Routed-By-ContentApi) for CD-related requests and then, use this header in the function to decide whether our partial router should handle the request and rewrite URL later on.

    using EPiServer.ContentApi.Routing;
    using System.Web;
    
    public class CustomContentApiRouteService : ContentApiRouteService
    {
        public override bool ShouldRouteRequest(HttpRequestBase request)
        {
            // By default, Requests which have accept headers 'application/json' will be routed.
            //if (request != null && request.AcceptTypes?.Contains(RouteConstants.JsonContentType) == true)
            //{
            //    return true;
            //}
    
            bool isRoutedByContentApi = false;
            if (bool.TryParse(request.Headers["Route-By-ContentApi"], out isRoutedByContentApi))
            {
                return isRoutedByContentApi;
            }
    
            return false;
        }
    }

Can I use Content Delivery API with SQL/Windows membership?

Content Delivery API OAuth package does not support SQL/Windows membership. Use Asp.Net Identity for authentication.

Do you find this information helpful? Please log in to provide feedback.

Last updated: Mar 24, 2021

Recommended reading