Accessing Route Request Info & Request Model from externally called API Controller

We have an API controller (inheriting ApiControllerBase) that is called from external parties to get data from Litium, e.g. for information feeds.

How do we use the Route Request Info & Request Model in this API controller? We need at least the PageService and the UrlService but probably others as well.

We cannot rely on anything sent in the request headers since calls are from external parties.

Litium version: 7.6 + accelerator

Maybe you could add an identifier to the query string in the call? Or have the route include an identifier [RoutePrefix("{channel}/api/endpoint].

Thanks. But doesn’t Litium/accelerator have a built-in way to infer channel/website from the URL? I would guess this is what the client-context emitter would need to do to render the channel/website JavaScript information. SomeService.GetWebsiteAndChannelFromUrl(Request.Uri)

But yes, otherwise we would have to provide the Litium services with channel/website IDs, either from configuration, or from the web API call itself.

How can we make the URL Service work in an ApiControllerBase? The exception thrown when using it says RouteRequestInfo must be populated; how do we satisfy that demand?

If it’s going through the Litium routing it will try and figure out the channel based on the URL, but not from a API call. You can use IChannelResolver.TryGet to get the RouteRequestLookupInfo object from the URL, but it might not work if you are using prefixes and the prefix isn’t included in the API URL.

If the object could be resolved, you can then set the property on _routeRequestLookupInfoAccessor.

Thank you. This worked perfectly.

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