Skip to content

Latest commit

 

History

History
55 lines (33 loc) · 3.65 KB

1. Web Services.md

File metadata and controls

55 lines (33 loc) · 3.65 KB

Web Services

Historical background

Traditional web applications (ASP, PHP, ASP.NET WebForms/MVC, Ruby on Rails etc.) are usually applications where everything is rendered server-side, and the client (i.e. the web browser) receives an HTML document. This architecture has a number of pros:

  • The client can be "lightweight", i.e. it only has to render the HTML.
  • If the application has to be modified, it can be done in a single place, i.e. on the server.

However, there are also cons:

  • This may result in a lot of overhead being passed between client and server, i.e. a small change in a page may result in a full page reload.
  • If the client isn't a web browser (instead, the client could be another program which is interested in the data the page is displaying), it will have to parse the result and extract exactly the data it needs to display, which is fragile and error-prone.

In recent years, a different architecture has become increasingly popular: the server doesn't render a full HTML page, but only delivers the data. The client must then take care of rendering the data, usually as HTML, but other clients (i.e. iOS/Android apps) can use different rendering methods.

Having an API means that other programmers can take the data exposed by the API, and do something with the data which the original authors/owners didn't think of in the first place, possibly by mixing other data from other APIs into the equation - often called a mashup. An example of this is Trendsmap, which mashes up Twitter Trending Topics with Google Maps to create a real time map of Twitter trends across the globe. A few other mashups made possible with API's can be found here.

In general, having an API is the most important decision you can make as a developer. How it is implemented is less important, in terms of platform, programming language, data format etc.

The number of APIs which are publicly available keeps growing, as well as pages which list official APIs. Collection of APIs in Iceland to contribute to the apis.is project it is possible to clone the project from github and add APIs.

Amazon

Sometime back around 2002 the founder of Amazon.com, Jeff Bezos, sent a memo to all the employes at the company and it read:

  • All teams will henceforth expose their data and functionality through service interfaces.
  • Teams must communicate with each other through these interfaces.
  • There will be no other form of communication allowed.
  • It doesn’t matter what technology they use.
  • All service interfaces, without exception, must be designed from the ground up to be externalizable. That is to say, the team must plan and design to be able to expose the interface to developers in the outside world. No exceptions.

He ended the memo by saying:

"Anyone who doesn’t do this will be fired.  Thank you; have a nice day!"

So all employes at Amazon had to communicate through APIs which was not a easy task but they learned a lot along the way as one employe said:

“Organizing into services taught teams not to trust each other in most of the same ways they’re 
not supposed to trust external developers.”

Types of web services

There are a number of different types of web services which have been developed over the course of years:

  • SOAP
  • REST
  • WCF

Recently, REST services are becoming more and more popular. We will spend most of the time looking at how to implement a RESTful web service using ASP.NET Web API.