Introduction

In this article we will describe how to create a downloadable Web API. Since we know that an API is a framework that can help to create HTTP services to provide the responses of the client request. HTTP services reaches a broad range of clients and also includes the browsers and mobile services. Here we describe the calling of the API application from the browser.

Step 1

Create the Blank Solution

Step 2

Create ASP. Net MVC Web API application

After creating the blank solution we can now add an ASP.Net Web API project.

Step 3

Add the Controller

Now use the following procedure to create the Controller:

Step 4

Write the following code in the helloController.cs:

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Net;
  5. using System.Net.Http;
  6. using System.Web.Http;
  7. namespace helloAPI.Controllers
  8. {
  9. public class helloController : ApiController
  10. {
  11. public string Get()
  12. {
  13. return "Mudita Rathore";
  14. }
  15. public string Get(string Id)
  16. {
  17. return "Mudita " + Id;
  18. }
  19. }
  20. }

Step 5

Now to call the Web API from the browser.

For calling the Web API, first we debug the code, then the result will look like this:

exe1.jpg

Now we access the URL "http://localhost:48909/api/hello".

exe2.jpg

Now we click on "Open" and select the browser to access the Web API.

Output

The result will look like this in the Mozilla Firebox browser:

res1.jpg