# Umbraco Api - Routing & 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: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

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

The question should be specific, self-contained, and written in natural language.
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.
