A RESTful chess service: part 2

Author: Dave Cassel  |  Category: Software Development

In part 1 of this series, I laid out my goals for a RESTful chess service, based on the RESTful Web Services book from the O’Reilly series. The authors present a procedure for designing services, the first two of which are:

  1. Figure out the data set
  2. Split the data set into resources

The use cases I’m looking to support are chess tournament directors (TD) reporting games during events and people searching for events, players, and games. That identifies my three major parts of the data set right there. There are other elements I could use. Chess has a standard notation for describing a game called PGN. Here’s an example from a small tournament I played in years ago:

[Event “First Saturday Quads”]
[Site “West Chester Chess Club”]
[Date “2003.02.01”]
[Round “1”]
[White “Joe Demetrick”]
[Black “David Cassel”]
[Result “1/2-1/2”]
[WhiteElo “1337”]
[ECO “D13b”]
1.d4 d5 2.c4 c6 3.Nf3 Nf6 4.cxd5 cxd5 5.Bf4 Bf5 6.e3 e6 7.Bb5+ Nbd7 8.O-O Qb6 9.Nc3 a6 10.Na4 Qxb5 11.Rc1 Be7 12.Ne5 Nxe5 13.Bxe5 O-O 14.b3 Rac8 15.Nb2 Ne4 16.g4 Nc3 17.Rxc3 Rxc3 18.gxf5 Rfc8 19.Qg4 f6 20.Nd1 Rc2 21.Bf4 exf5 22.Qxf5 Qc6 23.Kh1 Rxa2 24.Rg1 g6 25.Bh6 Bf8 26.Nc3 Qxc3 27.Qe6+ Kh8 28.Qxf6+ Kg8 29.Qe6+ 1/2-1/2

The format is pretty straightforward, I think. Metadata are at the top, followed by a list of moves in algebraic notation. If the move notation doesn’t make sense to you, don’t worry about it — that’s not important for this exercise.

This is a game I played in a small USCF event. You’ll notice the name of the event is “First Saturday Quads”. As you might guess, that’s not a unique name — other sites can have an event with the same name. Really it’s the combination of Event, Site, and Date that uniquely identify a particular tournament — and the date is a little dicey, since an event may span multiple days. This won’t be a problem for a TD uploading a game, as all the information is there. For search and browsing, I won’t have any explicit representation of a Tournament, although the service will allow a user to find all the games in a tournament.

The authors tell us that a resource is “anything interesting enough to be the target of a hypertext link.” They also list three kinds of resources web services commonly exposed.

1) Predefined, one-off resources

The given examples are top-level directories of available resources, or the home page of a web site. For my service, I will have a base resource that takes a collections approach, simply returning a list of links to the other resources available from the service.

2) A resource for every object exposed through the service

The objects I’ve decided to expose are events, players and games. Each event, player and game will be a unique resource available through the service. Events will be collections of games. We actually won’t be storing much information about players, only what is included in the game reports, so player resources will similarly be collections of games.

3) Resources representing results of algorithms

This service will define only one algorithm: search. The results will be collections of objects that match the search criteria. There will really be three ways to search, one for returning each type of object.

In the next part of this series, I’ll work through the remaining steps for the Game resource.

Tags: , , ,

Leave a Reply