Headless API with channel url prefixes

The headless API is by default accessed like this: domainname.com/HeadlessApi/StartPage. If you have a site with more than one language, is it possible to set up url prefixes or how do you recommend working with more than one language/channel?

I tried configuring domain name prefixes in Litium, it works for the website, but the headless API url is still domainname.com/HeadlessApi, I would want the url to be domainname.com/en/HeadlessApi

Litium version: 7.5.0

Is it that you wrote the controller in the headless api addon to supply this page ? ( http://domainname.com/HeadlessApi/StartPage )

@anusha.ganegoda No, its from the Litium.AddOns.HeadlessAPI project. And that is just an example, the same is true for all endpoints. How is the Headless API meant to work with more than one language?

It is a starting point for you to build your own headless API website. The add-on is given in source code format. As you can see, you can modify the controller endpoint to accept the channel in the url.

http://domainname.com/HeadlessApi/StartPage/en can be made, if you add it to the controller endpoint.

 /// <summary>
    /// Endpoint for start page.
    /// </summary>
    /// <seealso cref="Litium.AddOns.HeadlessApi.Controllers.HeadlessApiControllerBase" />
    [RoutePrefix(Routes.StatePage)]
    public class StartPageController : HeadlessApiControllerBase
    {
        private readonly StartPageModelBuilder _startPageModelBuilder;
        private readonly UserSessionService _userSessionService;

        public StartPageController(StartPageModelBuilder startPageModelBuilder, UserSessionService userSessionService)
        {
            _startPageModelBuilder = startPageModelBuilder;
            _userSessionService = userSessionService;
        }

        /// <summary>
        /// Gets the start page
        /// </summary>
        /// <param name="webApiContext">The web API context.</param>
        /// <returns></returns>
        [Route("{sessionId?}", Name = "GetStartPage")]
        [HttpGet]
        [ResponseType(typeof(StartPageModel))]
        public IHttpActionResult Get(WebApiContext webApiContext)
        { 
            var model = _startPageModelBuilder.Build(webApiContext);
            if (model == null)
            {
                return NotFound();
            }
            return Ok(model);
        }
    }

Yes, ofcouse I can do that. I was just hoping this was something considered in the Headless project starting point. But good, then I know, I will try to figure out a clever solution for this.

1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.