Skip to main content

Web-API - RESTful Services on Microsoft .net for building Ubiquitous web world

It's been very interesting to note about the fantastic things happening in the world of web development.
Finally, we got the solid framework for building RESTful services on Microsoft platform. Let's have a very  quick look at the basic detail.

REST [Representation State Transfer Protocol]
          A representation is a opaque string of bytes that is effectively manifestation of a resource. REST was never about pretty URLs. The whole point of the hypermedia is that client should not need to know how to construct these URLs in the first place. For your clients, they are just STRINGS.

          Web-API can be used when you have clients which consumes data from server over HTTP.
Now a days, lot of browser applications are rich clients with web server returns some static html and then may be it uses client side framework like jquery, backbonejs or knockoutjs and makes calls back to server to pull data to execute some client-side functionality.

Web-API's role is not just about serving data, it's about accepting data and returning data in different formats and you might have clients which are not just browsers. They can be mobile devises. Web API is for enabling rich set of clients to be able to consume information. Whereas ASP.net traditionally been about just servicing html. We can do other things but it's not tailored for non browser based clients.
In case of clients consuming WebAPI using JS frameworks, it's not just about traditional html, it's like tiny program that is getting executed in your browser. That's the primary difference.

MVC is like page oriented whereas whereas WebAPI is not. What it means if that in MVC, you can have a url for editing some information like http://bla.com/Employee/Edit. in this example edit will be your action. But, in WebAPI, you will be dealing with standard http verbs like get, post, put and delete. The primary difference in webAPI is you will be interacting with a resource using these http verbs:
If you wanna pull data - Get

If you wanna push data - Post
If you wanna update state of resource  - Put   


That's the real difference. With Web API you will be sticking to http semantics. If you want to build something like facebook(just as in example), you can leverage power of web api because you might want it be ubiquitous.Some clients may want xml format, some may want json or some may want pdf, web api actually shipped with lots of these formatters.

Representations can come in many different formats and the process of selecting the best format for a given client is called "Content Negotiation". If you want to do it with MVC, it might be lot more plainful. You can write your custom formatter.

Ruby, phython are the more kind of dynamic languages which has concept of httpclient. You can just use it to make http requests and work with http response. In .net world we don't have good answer till web api has born. We have strong abstraction for httprequest. It also solved the problem of unit testing a http service.
You might want to accept only few header, with web api you can easily handle these kind of things.

Finally, for things like hosting, you can host it in IIS or you can do self hosting in a process or you can also use open source web servers like kayak.

Popular posts from this blog

Remote debugging Windows azure cloud service - Worker Role

Remote debugging Windows azure cloud service - Worker Role Very recently I was working on design and development of a worker role component of cloud service. Locally debugging worker role is pretty easy. You just need to know that you need to set Cloud project as a start-up project and ready to go. Problem is when you deploy worker role to azure and trying to troubleshoot an unknown issue.  Thankfully we have remote debugging enable for cloud services – both web and worker roles. This is really handy tool to remotely debug without having to putting a lot of tracing and digging into it. However, remote debugging in worker role/web role requires few steps to be followed: Make sure you are debugging from same machine where you published Make sure to turn on Remote debugger on while you publish (This should be turned off for Production publish profiles) Make sure to Select Debug mode With all the above settings after you publish, you should be able to Attach D

Differences between Object Serialization and Deserialization?

Serialization = putting the relevant state of the object into a streamable representation. That can mean converting it to a byte stream. This does not necessarily include copying every member variable into the stream. Deserialization = restoring an object from a serial representation and ensuring the invariants of the object. Deserialization can be thought of a separate constructor for the object.