---
title: "How many types of Action Methods are in Web API?"  
description: "How many types of Action Methods are in Web API?"  
author: "Ravi Vishwakarma"  
published: 2023-03-23  
updated: 2023-06-04  
canonical: https://www.mindstick.com/forum/157553/how-many-types-of-action-methods-are-in-web-api  
category: "asp.net mvc"  
tags: ["asp.net", "api(s)"]  
reading_time: 2 minutes  

---

# How many types of Action Methods are in Web API?

[Please explain](https://www.mindstick.com/forum/344/hi-rohith-i-am-new-for-mvc-please-explain-how-to-set-implicitly-isauthenticated-true) [anyone](https://www.mindstick.com/articles/23207/how-to-find-the-best-fit-job-for-anyone) to me.

## Replies

### Reply by Aryan Kumar

There are three types of action methods in Web API:

- **Void** action methods do not return anything. They are typically used for actions that do not need to return any data, such as actions that simply log a message or perform some other action that does not need to be returned to the client.
- **Primitive type or complex type** action methods return a primitive type, such as an integer or a string, or a complex type, such as a class or a collection. These types of action methods are typically used for actions that return data to the client, such as actions that return a list of items or a single item.
- **HttpResponseMessage** action methods return an instance of the HttpResponseMessage class. This class provides a way to control the HTTP response, such as the status code, headers, and content. These types of action methods are typically used for actions that need to have more control over the HTTP response, such as actions that need to return a custom error message or a custom response body.

The type of action method that you use will depend on the specific needs of your application. For example, if you need to return a list of items to the client, you would use a primitive type or complex type action method. If you need to return a custom error message or a custom response body, you would use an `HttpResponseMessage` action method.

Here are some examples of action methods:

Code snippet

```plaintext
// Void action method
public void Get()
{
    // Do something
}

// Primitive type or complex type action method
public string GetUserName()
{
    // Get the user name from the database
    return user.Name;
}

// HttpResponseMessage action method
public HttpResponseMessage GetError()
{
    // Create a response message with an error status code
    HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.BadRequest);
    response.Content = new StringContent("The request is invalid.");
    return response;
}
```


---

Original Source: https://www.mindstick.com/forum/157553/how-many-types-of-action-methods-are-in-web-api

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
