> For the complete documentation index, see [llms.txt](https://docs.umbraco.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.umbraco.com/umbraco-cms/13.latest/reference/routing/umbraco-api-controllers/routing.md).

# Umbraco Api - Routing & Urls

How api controllers are routed and how to retrieve their URLs

*This section will describe how Umbraco Api controllers are routed and how to retrieve their URLs*

## Routing

Like Surface Controllers in Umbraco, when you inherit from the base class `Umbraco.Cms.Web.Common.Controllers.UmbracoApiController` we will auto-route this controller so you don't have to worry about routing at all.

All locally declared Umbraco api controllers will be routed under the URL path of:

\~/Umbraco/Api/\[YourControllerName]

All plugin based Umbraco api controllers will be routed under the URL path of:

\~/Umbraco/\[YourAreaName]/\[YourControllerName]

* [More information on implementing these controllers](/umbraco-cms/13.latest/reference/routing/umbraco-api-controllers.md).

## Urls

We've added some handy `UrlHelper` extension methods to help you retrieve the Url of your Umbraco Api controllers. The extension methods are found in the class: `Umbraco.Extensions.UrlHelperExtensions` so you'll need to ensure you have the namespace `Umbraco.Extensions` imported. You will also need to inject `UmbracoApiControllerTypeCollection`, if you want to use any of the overloads that require it.

The method overloads are:

```csharp
string GetUmbracoApiService<T>(UmbracoApiControllerTypeCollection umbracoApiControllerTypeCollection, string actionName)
string GetUmbracoApiService<T>(UmbracoApiControllerTypeCollection umbracoApiControllerTypeCollection, Expression<Func<T, object>> methodSelector)
string GetUmbracoApiService(UmbracoApiControllerTypeCollection umbracoApiControllerTypeCollection, string actionName, Type apiControllerType)
string GetUmbracoApiService(string actionName, string controllerName)
string GetUmbracoApiService(string actionName, string controllerName, string area)
```

The most consistent way to retrieve a Url is to use your controller's type, and an expression to select the action. Example of retrieving a URL in a view:

```csharp
@using RoutingDocs.ApiControllers
@inject Umbraco.Cms.Core.UmbracoApiControllerTypeCollection _controllers;

@(Url.GetUmbracoApiService<ProductsController>(_controllers, controller => controller.GetAllProducts()))
```

Generally a UrlHelper instance will be available on most base classes like Controllers and Views, and you shouldn't have to create it manually, but if you need to you can, by injecting `IUrlHelperFactory` and `IActionContextAccessor` and then use the factory like so:

```
var urlHelper = _urlFactory.GetUrlHelper(_actionContextAccessor.ActionContext);
var url = urlHelper.GetUmbracoApiService("GetAllProducts", "Products");
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.umbraco.com/umbraco-cms/13.latest/reference/routing/umbraco-api-controllers/routing.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
