---
title: "What is the purpose of the [ApiController] attribute?"  
description: "What is the purpose of the [ApiController] attribute?"  
author: "Sandra Emily"  
published: 2023-08-28  
updated: 2023-08-29  
canonical: https://www.mindstick.com/forum/159693/what-is-the-purpose-of-the-apicontroller-attribute  
category: ".net core"  
tags: ["asp.net", ".net core", ".net core api"]  
reading_time: 2 minutes  

---

# What is the purpose of the [ApiController] attribute?

What is the [purpose](https://yourviews.mindstick.com/view/247/no-fail-policy-failing-its-purpose) of the [ApiController] [attribute](https://www.mindstick.com/blog/221/attributes-reflection)?

## Replies

### Reply by Aryan Kumar

The `ApiController` attribute in .NET Core is used to mark a class as an API controller. API controllers are classes that handle HTTP requests and responses. They are used to create RESTful APIs.

The `ApiController` attribute has the following properties:

- `RoutePrefix`: The route prefix for the controller. This is the part of the URL that will be used to access the controller.
- `ApiVersion`: The API version for the controller. This is used to indicate the version of the API that the controller supports.
- `AllowAnonymous`: Whether or not anonymous users are allowed to access the controller.

The following is an example of a class that is marked with the `ApiController` attribute:

C#

```plaintext
[ApiController]
[RoutePrefix("/products")]
public class ProductController : ControllerBase {

  // ...
}
```

This class is an API controller that can be accessed at the `/products` endpoint. Anonymous users are allowed to access this controller.

Here are some additional tips for using the `ApiController` attribute:

- Use the `ApiController` attribute on all classes that are API controllers. This will help to ensure that your code is organized and easy to maintain.
- Use the `RoutePrefix` property to specify the route prefix for each controller. This will help to keep your URLs organized and easy to understand.
- Use the `ApiVersion` property to specify the API version for each controller. This will help to ensure that your API is backward compatible.
- Use the `AllowAnonymous` property to control whether or not anonymous users are allowed to access each controller.


---

Original Source: https://www.mindstick.com/forum/159693/what-is-the-purpose-of-the-apicontroller-attribute

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
