Chapter 2. XML Hypermedia

They that mistake life’s accessories for life itself are like them that go too fast in a maze: their very haste confuses them.

- Seneca

In this first hands-on design chapter, a simple read-only, XML-based media type will be used to show how to convert a use case scenario into a successful design. Once the design is completed, example server and client implementations will be explored including one client example that shows how an autonomous web bot can successfully choose from the available hypermedia links in order to reach a final goal.

Scenario

For the first project, what is needed is a web-enabled “Maze Game.” In this game, clients should be able to request a maze to play and then be able to navigate from a predetermined starting point through the maze to the exit. Clients should be able to use the cardinal directions (north, south, east, and west) to move through a two-dimensional space. Mazes could be of any size or shape; use any configuration of rooms and doorways.

What is needed is a media type that can express the state of a given client’s traversal through the maze from start to finish. A minimum set of requirements for this media type design should allow client applications (given an initial starting URI) to:

  • Discover a list of available mazes

  • Select one of the available mazes to play

  • Recognize the existing doorways in each cell of the maze

  • Navigate through a selected doorway into the next cell

  • Recognize and navigate through the exit when it appears

Get Building Hypermedia APIs with HTML5 and Node now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.