Skip to main content

ASP.NET Web API Explained


ASP.NET Web API Explained

What is Web API?

The ASP.NET Web API is a framework that makes it easy to build HTTP services that reach a broad range of clients, including browsers and mobile devices.

The ASP.NET Web API is an ideal platform for building Restful applications on the .NET Framework.

Why do we advocate for the use of Web API?


Nowadays, most mobile devices, browsers and tablets are the medium for accessing most of the internet and also, people are using mobile apps the most and to provide data to apps.

 When are we to use Web API?


Whenever we want to expose the data/information of our application to our clients and other people, then those people can use our data and interact with the data/information we expose to them.

For instance, a mobile application requires a service, HTML 5 also requires a service as well as desktop and tablets require services. Most current device apps require Web API services.

The ASP.Net Framework leverages both web standards such as HTTP, JSON and XML and it provides a simple way to build and expose REST based data services.

Some core concepts of ASP.Net MVC are similar to the ASP.Net Web API such as routing and controllers.

Building a Web API


Let us develop an ASP.NET Web API using Visual Studio 2019.

Create a new Project and select ASP.NET Web Application (.Net Framework) and click no Next as shown below



Provide the name of the project as in CsharpNaijaWebAPI and click on Create Button as shown below

Click on Change link button from the top right corner and on Individual User Accounts and then click on as shown below

Select MVC and click on Create button as shown below

A new ASP.NET MVC application we be created as shown below

New let us create a Web API in the solution that we created as in the above.

Right click on the solution name select Add then New Project as shown below

 Select ASP.NET Web Application (,NET Framework) as we did in the above.

Change the authentication type to Individual User Accounts for User authentication and select the Web API and click on create button as shown below


Now we have created two projects in our solution namely; CshapnaijaWebAPI and WebAPI

Expand the Controllers folder and double click on ValuesController to see the default controller action methods generated when creating the Web Api.



We have successfully added a Web API controller to your application.

Now you can build and run the application, the output is as shown below

Click on the API menu to see the default Api controller generated for us as shown below

It's easy to configure it as a Web API.


The ASP.Net MVC  and ASP.Net Web API makes heavy use of convention for configuration to lighten the work load for creating the services.

From the code snippet below we can see the http verbs for CRUD operation on our data


The HTTP actions and their corresponding CRUD operations are:
  • GET (Read)
    Retrieves the representation of the resource.

  • PUT(Update)
    Update an existing resource.

  • POST (Create)
    Create new resource.

  • DELETE (Delete)
    Delete an existing resource.
We will continue with ASP.NET Web API in the next article

Hope this article really throw some light on the concept of Web API



Comments

Popular posts from this blog

The String.Join Method in C# Explained

The String.Join Method in C#   The string.Join concatenates the elements of a specified array or the members of a collection, using the specified separator between each element or member. Overloads of string.Join Method Description Join(Char, Object[]) Concatenates the string representations of an array of objects, using the specified separator between each member. Join(Char, String[]) Concatenates an array of strings, using the specified separator between each member. Join(String, IEnumerable<String>) Concatenates the members of a constructed IEnumerable<T> collection of type String, using the specified separator between each member. Join(String, Object[]) Concatenates the elements of an object array, using the specified separator between each element. Join(String, String[]) Concatenates all the elements of a string array, usi...

Most Popular Programming Languages in 2020

Most Popular Programming Languages in 2020 In this blog post, you will learn about the most popular programming languages in 2020 for creating the best web applications. Check its pros and cons. Analyzed by technostacks Not very long ago, just a few people were considered to be computer programmers, and the general public viewed them with awe. In this digital age that we are now living in, however, a large number of IT jobs need a solid grasp of one or more programming languages. Whether one wants to develop a mobile app or get a certification for having programming knowledge, or even to learn new skills, one needs to opt for the right programming language. Below mentioned eight most popular programming languages which are in demand for software development and web applications. This is the most used programming languages in 2019 and will be in 2020. For each, there is little information about the language, benefits and its complexity, as well as about its usage. One must...

HashTable in C# with Example

  HashTable in C# with Example Hashtable  is used to store a collection of key/value pairs of different  data types  and are organized based on the hash code of the key.   Generally, the hashtable object will contain buckets to store elements of the collection. The bucket here, is a virtual subgroup of elements within the hashtable and each bucket is associated with a hash code, which is generated based on the key of an element.   In C#, hashtable is same as a  dictionary  object but the only difference is that the  dictionary  object is used to store a key-value pair of same  data type  elements.   When compared with  dictionary  object, the hashtable will provide a lower performance because the hashtable elements are of object type so the boxing and unboxing process will occur when we are storing or retrieving values from the hashtable.   C# HashTable Declaration Hashtable is a non-generic type...