An Introduction to Web API

ASP.NET Web API is a framework for building HTTP bases services on top of the .NET Framework.

These services can be consumed by a variety of clients which are the following:

  • Browsers
  • Mobile Apps
  • IoT devices
  • Desktop applications

What are RESTful Services and how do they differ from SOAP?

REST stands for Representational State Transfer. It was introduced by Roy Fielding in 2000 as part of his doctoral dissertation. REST is essentially an architectural pattern for creating services. A useful set of rule as it were.

RESTful services are fundamentally different than SOAP-based services, because they don’t attempt to achieve transport neutrality. In fact, RESTful services typically embrace HTTP as the only “Web” transport. This is because, RESTful design doesn’t say anything about which implementation technologies you use; however, in practice, HTTP is the only commonly used protocol.

With REST, you model services as resources, and you give them unique identifiers in the form of URI’s, and then you interact with those resources through a standard uniform interface, or service contract

REST architectural pattern specifies a set of constraints that a system should adhere to.

REST Architectural Goals

  • Visibility
  • Reliability
  • Scalability
  • Performance
  • Portability
  • Simplicity

REST Design Principles

  • Everything is a Resource (E.g. Departments, Employees etc.)
  • Each Resource is identifiable by Unique URI
  • Use the standard HTTP Verbs
  • Allow multiple representations for the same Resource
  • Communication should always be stateless
  • Content Negotiation (JSON, XML, Text, JPEG etc.)

REST Constraints

  • Client Server
  • Stateless (Communication between Client and Server must be stateless. In other words, nothing should be stored on the server that is related to the client)
  • Cacheable (Persisting data that is frequently accessed by the client)
  • Uniform Interface
  • Layered System
  • Code on Demand

When a user sends a request to the server, the server parses the request, builds the response to return the payload to the client. The response represents a state and HTTP response code that is typically used to inform the client of the result.

There are five types of HTTP status codes which are the following:

  • 100’s (Informational)
  • 200’s (Success)
  • 300’s (Redirection)
  • 400’s (Client Errors)
  • 500’s (Server Errors)

Below is a complete list of HTTP status codes:

What about WCF? How does it measure up to Web API?

Web API is best suited for resource-oriented services using HTTP. WCF on the other hand was created to develop SOAP-based services and bindings.

Web API is light weight, simple and fast and requires little ceremony to get up and running as compared to WCF.

As you can see in the image below, there are different nodes that are connected into one logical connected system. This is typically achieved by Services. Services expose units of functionality via messaging. This interoperability is achieved via standard protocols and message formats.

You can also go to Microsoft Docs to find out more about Web API.

Happy reading 🙂

About Obi Oberoi

Obi Oberoi is an Independent Consultant, Developer and a Life-Long student of continuous learning. Obi enjoys to code, read, and hang out with techies and geeks!
This entry was posted in .NET, Web Services. Bookmark the permalink.