You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

Representational State Transfer, from now on called REST, is actually not really a protocol, but more of a style of communication. Great advantages of having no protocol are simplicity, visibility and performance. A disadvantage is that the communication is not strictly defined, and must be informally be documented in a sufficient way.

Calling a REST service

Calling a REST service is done by URL. This means that all information that the server needs to process your request is placed as parts in this URL. (This is not entirely true due to http headers, but close enough). Here is an example of a REST web service that allows you to receive live information on American airports:

http://services.faa.gov/airport/status/IAD?format=xml

Go ahead, click on it to see what the current conditions at Washington Dulles Airport are. Your answer may look something like this:

<AirportStatus>
    <Delay>false</Delay>
    <IATA>IAD</IATA>
    <State>District of Columbia</State>
    <Name>Washington Dulles International</Name>
    <Weather>
        <Visibility>10.00</Visibility>
        <Weather>Overcast</Weather>
        <Meta>
            <Credit>NOAA's National Weather Service</Credit>
            <Updated>4:52 AM Local</Updated>
            <Url>http://weather.gov/</Url>
        </Meta>
        <Temp>45.0 F (7.2 C)</Temp>
        <Wind>South at 4.6mph</Wind>
    </Weather>
    <ICAO>KIAD</ICAO>
    <City>Washington</City>
    <Status>
        <Reason>No known delays for this airport.</Reason>
        <ClosureBegin/>
        <EndTime/>
        <MinDelay/>
        <AvgDelay/>
        <MaxDelay/>
        <ClosureEnd/>
        <Trend/>
        <Type/>
    </Status>
</AirportStatus>

This answer is in XML format. The corresponding XSD (explained in Chapter 2: Simple Object Access Protocol (SOAP)) is hopefully placed in the documentation of the web service. If not, you will have to generate your own xsd on this answer and hope that it is correct. This is directly the largest drawback of REST services.

Now, lets look again at the URL: http://services.faa.gov/airport/status/IAD?format=xml It consists of several element.

  • The first part is the location of the webservice (http://services.faa.gov)
  • The next part are called fragments (/airport/status/IAD). These fragments are used to supply information to the web service. These particular fragments indicate that you want to retrieve the airport status from the airport with code IAD. You can request information on a different airport by changing the URL, for example: http://services.faa.gov/airport/status/JFK?format=xml.
  • Everything after the '?' are arguments. They essentially are also just information for your request. In this example the argument determines the answer format. It was set to xml in above example. Try a json format by following this url: http://services.faa.gov/airport/status/JFK?format=json

  • No labels