RESTful Communications

RESTful Web Service: Where and Why?

A RESTful web service has been created at https://sharedsapience.website/bespoke_php_files/planetary_statistics.php. The purpose of this RESTful web service is to output statistics relating to each of the nine planets in our solar system.

RESTful Web Service: Pluto statistics in 'json' format.
An image of the planetary statistics output in response to a request string specifying ‘Pluto’ as the planet and ‘json’ as the format.

RESTful Web Service: What?

The following planetary statistics are output by this RESTful web service: planet name; distance from the sun (in metres and kilometres); distance from each of the other eight planets (in metres and kilometres); and the time it takes sunlight to travel to the planet.

The statistics can be output in the following formats: html; text; json; and xml.

RESTful Web Service: Pluto statistics in html format.
An image of the planetary statistics output in response to a request string specifying ‘Pluto’ as the planet name and ‘html’ as the format.

RESTful Web Service: How?

The planetary statistics have been calculated based on the following assumptions:

    • The speed of light is: 299,792,458 metres per second
      [Source: www.quora.com]
    • An astronomical unit (au) is: 149,597,870,700 metres [Source: wikipedia.org]
    • The distance [measured in astronomical units] of each of the planets from the sun is: Mercury – 0.387 au; Venus – 0.723 au; Earth – 1 au; Mars – 1.52 au; Jupiter – 5.20 au; Saturn – 9.58 au; Uranus – 19.20 au; Neptune – 30.05 au; and Pluto – 39.48 au. [Source: nasa.gov]
RESTful Web Service: Pluto statistics in 'xml' format.
An image of the planetary statistics output in response to a request string specifying ‘Pluto’ as the planet and ‘xml’ as the format.

Communicating with the RESTful web Service

The RESTful Web Service requires two parameters to be passed in the request string: planet and format; both parameters are case-insensitive.

The correct request string syntax can be expressed thusly:
https://sharedsapience.website/bespoke_php_files/planetary_statistics.php?planet=PLANET&format=FORMAT

PLANET can be any of the nine planets in our solar system: Mercury; Venus; Earth; Mars; Jupiter; Saturn; Uranus; Neptune; or Pluto. FORMAT can be any of the following output types: html; text; json; or xml.

If the request string is correctly-formed, the RESTful Web Service responds with a ‘200 OK’ HTTP header and outputs relevant statistics for the desired planet in the specified format. If a malformed request string is received, the RESTful Web Service responds with a ‘400 Bad Request’ HTTP header and outputs a custom error message detailing the expected request string formulation.

RESTful Web Service: Pluto statistics in 'text' format.
An image of the planetary statistics output in response to a request string specifying ‘Pluto’ as the planet and ‘text’ as the format.
RESTful Web Service: response to a malformed request
An image of the RESTful Web Service’s ‘400 Bad Request’ response to a malformed request string.

Forty-year-old father of three wonderful children [William, Seth, and Alyssa]. Works as an Assistant Technical Officer in the Sterile Services Department of Treliske Hospital, Cornwall. Enjoys jogging, web design, learning programming languages, and supporting Arsenal FC. Obtained a BA degree in English from the University of Bolton in 2008, and has continued to gain qualifications in a diverse range of subjects thereafter.

Tagged with: ,
Posted in RESTful Communications

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: