Eric lippert - Amazon Web Services
Eric lippert - Amazon Web Services
Eric lippert - Amazon Web Services
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
• In the diagram we just saw, a user is sitting at the computer and types in a URL in the browser.<br />
Notice that apart from the URL he also types in /suprotimagarwal which tells the server<br />
‘something’.<br />
• The browser sends this request over HTTP to (GET) the actual site. The discovery process of<br />
www.twitter.com leverages the routing mechanism of the internet and it happens over port 80<br />
using HTTP.<br />
• The request is eventually sent to the Twitter server where it is processed by a web application<br />
running a service on top of HTTP at port 80.<br />
• This service then interprets ‘suprotimagarwal’ in the URL as a request to GET (as in the HTTP<br />
request keyword) the profile of suprotimagarwal. Thus it makes appropriate backend calls to<br />
retrieve the user profile data and sends it back to the requestor. In this case the user’s<br />
browser renders the data that came in. Note, sometimes, the raw data may not be sent back,<br />
instead the data is used to build the respective view and the complete view (in html) may be<br />
returned, but in context of <strong>Web</strong> API, it’s not a view, only the data. Keep the term ‘Content Type<br />
Negotiation’ in mind, we will circle back to it in the next section.<br />
Overall the idea of <strong>Web</strong> API is to offer services that work seamlessly over HTTP as we saw<br />
above. This is a great way to build public APIs for multiple client platforms.<br />
Http and Content Types<br />
Whenever we think of HTTP URLs and web browsers, we picture<br />
HTML being received by the browser and then rendered.<br />
However, there are instances when our browser renders an<br />
image by itself, or plays music or shows a PDF document in<br />
the browser itself. These are instances where data/content<br />
other than html was sent over and the browser ‘understood’ the<br />
‘Content Type’ and acted appropriately. For example, if we have<br />
link to a PDF and the browser has a plugin for it, it can directly<br />
display the PDF (in browser).<br />
When you build <strong>Web</strong> API based services, you can return data<br />
as JSON by default. However you can send out other types of<br />
content as well. For example, if you are sending out Calendar<br />
information, you can send it out as an iCal, when sending out<br />
graphs data you can send out the rendered image and so on.<br />
What type of data is acceptable to the client and what can the<br />
server provide is a ‘negotiation’ that happens between the client<br />
and the server before either a content type is agreed upon or a<br />
406 (Not Acceptable) error is sent by the server implying, it<br />
cannot provide data in any of the requested Content Types.<br />
Media Formatters and Content<br />
Types<br />
As I mentioned briefly above, <strong>Web</strong> API services return data in<br />
JSON or XML. This is because the data returned by the<br />
Controller is converted into JSON or XML by a component<br />
referred to as Media Formatter. <strong>Web</strong> API has two of these out<br />
of the box, no points for guessing they are for JSON and XML<br />
formats.<br />
DNcmagazine www.dotnetcurry.com | 63