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

Debugging code running on Remote machine

Before performing below steps, you need to make sure you have pdb files matching dll version on the remote machine.  Open below folder in your remote machine C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\Remote Debugger\x64  Open that folder and launch as admin  msvsmon.exe  Select all options to allow firewall From Tools > Options  - Keep the settings to default (as shown below) and click ok.  At this point your remote debugger is all set. You need to connect from Visual Studio by entering Machine IP: Port (4022) 

Using IsInRole() with Forms Authentication

A Little background…. Page object provides User [ System.Security.Principal.IPrincipa l ] in order to access to the information about the current authenticated user. User is having following two important members. These members provide way to implement Role-based authorization programmatically. Identity [Property] [ System.Security.Principal.IPrincipal.Identity ] – This property provides important members like AuthenticationType, IsAuthenticated, Name. IsInRole [Method] [ System.Security.Principal . IPrincipa l ] – This method takes single parameter that is string value of Role for which to check the membership.

SharePoint yammer integration error: System.Exception: Unable to load the web part. IsEdit: False, IsAsync: False, FormMode: Invalid, SharedProperties: {"site_url":"http:// ","service_account":"true","webpart_guid":" ","iframe":"true","version":" "} at Yammer.SharePoint.WebParts.YammerAppsWebPart.CreateChildControls()

Hi there,  if you are searching for below error ..  System.Exception: Unable to load the web part. IsEdit: False, IsAsync: False, FormMode: Invalid, SharedProperties: {"site_url":"http:// ","service_account":"true","webpart_guid":" ","iframe":"true","version":" "} at Yammer.SharePoint.WebParts.YammerAppsWebPart.CreateChildControls()  The solution you can try could be disabling uploading file attachments to yammer. Below are the steps: 1.Select your webapplication from CA > Manage web apps 2.On the Ribbon>Yammer>Yammer Settings 3.Deselect 'Enable uploading file attachments to Yammer' 4.Click 'Save Settings'. And you are done! You can now add yammer web part to page and can check again.