In this article we will see HTTP Response Message as return type for the API method. This is part three of the article series. Before reading this article, I would recommend reading the following previous parts.
HTTPResponseMessage feature is provided by WebAPI framework which is used to create HTTP services. It helps us to send responses in different ways. HTTPResponse message is used to return data as well as some user friendly messages like:
| Status Code | Status Message |
| 200 | OK |
| 201 | Created |
| 404 | Not Found |
HTTPResponseMessage in Web API
Now let’s see step by step implementation of HTTPResponseMessage:
- Open Visual Studio Editor
- Select ‘File’ menu, expand ‘New’ and click on ‘Project…’

- Expand ‘Visual C#’ and select ‘Web’ from the left panel
- Select ‘ASP.NET Web Application’
- Provide appropriate name of the application and select the location
- Click on ‘OK’ button,

- Select ‘Empty’ as a template and check ‘Web API’ check box
- Press ‘OK’ button and it will create an empty Web API project.

- Right click on ‘Controllers’, expand ‘Add’ and click on ‘Controller…’

- Select ‘Web API 2 Controller with read/write actions’ and press ‘Add’ button, which will add all HTTP methods.

- Provide appropriate name and press ‘Add’ button,

- Controller is created with read / write actions,
- namespace HTTPResponseMessage.Controllers
- {
- public class ServiceController: ApiController
- {
- // GET: api/Service
- public IEnumerable < string > Get()
- {
- return new string[]
- {
- "value1",
- "value2"
- };
- }
- // GET: api/Service/5
- public string Get(int id)
- {
- return "value";
- }
- // POST: api/Service
- public void Post([FromBody] string value) {}
- // PUT: api/Service/5
- public void Put(int id, [FromBody] string value) {}
- // DELETE: api/Service/5
- public void Delete(int id) {}
- }
- }






Bijendra RathodPosted Jun 13, 2019, 7:39 AM
How to write post,put,delete method using request url in c#? plz help me..(note: the request url is "http://ide1.vivasa.in:59725/bag" .
Anil Kumar PradhanPosted Jul 8, 2016, 2:57 AM
Good article