Game Service :: Specification

The following table lists the function currently provided and the the means by which they are accessed.

Function Method URI Body Parameters
List Games GET /GameService/Scores  
Create Game PUT /GameService/Scores/<game-id>  
Record Score POST /GameService/Scores/<game-id>
name
= The player's name
score
= The score achieved
Get Top Ten Scores GET /GameService/Scores/<game-id>  
Delete Game DELETE /GameService/Scores/<game-id>  

It is possible to access the service using your web browser. In fact, the high scores for each currently registered game are available here.

Let's get down to the fine details. It should be noted that with the exception of Record Score, all of the functions are idempotent. The implication of this is that repeated operations have the same side effects as a single operation.

List Games

Request:

GET /GameService/Scores

Response:

HTTP/1.1 200 OK

The response body will contain an XML document containing a list of all available games, for example:

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="/GameService/Resources/ListGames.xsl"?>
<Games>
    <Game id="PacMan"/>
    <Game id="LunarRescue"/>
    <Game id="SpaceInvaders"/>
</Games>

Note: The presence of whitespace and formatting is subject to change.

Create Game

Request:

PUT /GameService/Scores/<game-id>

Where <game-id> is the id of the game, which must only contain alpha numeric characters. The request will be ignored if the game already exists.

Response if game did not previously exist:

HTTP/1.1 201 Created

Response if game already existed:

HTTP/1.1 204 OK

Response if creation failed:

HTTP/1.1 500 Internal Server Error

Record Score

Request:

POST /GameService/Scores/<game-id>

Where <game-id> is the id of the game. If the game does not exist, it will be created.

Two parameters are required in the request body:

name
= The player's name
score
= The score achieved

Response if score recoding succeeded:

HTTP/1.1 204 OK

Response if score recoding failed:

HTTP/1.1 500 Internal Server Error

Get Top Ten Scores

Request:

GET /GameService/Scores/<game-id>

Response if game exists:

HTTP/1.1 200 OK

Response if games does not exist:

HTTP/1.1 404 Not Found

The response body will contain an XML document containing details of the top ten scores, for example:

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="/GameService/Resources/TopTen.xsl"?>
<TopTen game="pacman">
    <Entry rank="1" name="AMY" score="1850"/>
    <Entry rank="2" name="BARRY" score="580"/>
    <Entry rank="3" name="CATHY" score="520"/>
    <Entry rank="4" name="DAVID" score="345"/>
    <Entry rank="5" name="ELLEN" score="220"/>
    <Entry rank="6" name="FRED" score="190"/>
    <Entry rank="7" name="GRACE" score="190"/>
    <Entry rank="8" name="HENRY" score="80"/>
    <Entry rank="9" name="IVY" score="20"/>
    <Entry rank="10" name="JOSEPH" score="202"/>
</TopTen>

Note: The presence of whitespace and formatting is subject to change.

Delete Game

Request:

DELETE /GameService/Scores/<game-id>

Where <game-id> is the id of the game. The request will be ignored if the game does not exist.

Response if game deleted:

HTTP/1.1 204 OK

Response if deletion failed:

HTTP/1.1 500 Internal Server Error