Cover by Subbu Allamaraju

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

O'Reilly logo

5.5. How to Use Links to Manage Application Flow

One of the key applications of hypermedia and links is the ability to decouple the client from learning about the rules the server uses to manage its application flow. The server can provide links containing application state, thereby using hypermedia as the engine of application state.

Problem

You want to know how to keep clients decoupled from the business logic used to implement the flow of the application.

Solution

Design each representation such that it contains links that help clients transition to all the next possible steps. If the server needs to carry forward state from one step to the next, encode the state in links as described in Recipe 1.3.

Discussion

Imagine a web service that manages an employee hiring process. This process has multiple steps, such as (a) enter candidate details, (b) check references, (c) conduct background security checks, and (d) make an offer. Each step must happen in sequence. You can use the resources and URIs shown in Table 5-2 to implement this sequence. The token {id} in these URIs is the candidate ID.

Table 5-2. URIs for employee hiring process

Method

URI

Purpose

POST

http://www.example.org/hires

Create a candidate resource.

POST

http://www.example.org/hires/{id}/refs

Submit reference comments.

POST

http://www.example.org/hires/{id}/bgchecks

Submit background check results.

POST

http://www.example.org/hires/{id}/hire

Make an offer.

POST

http://www.example.org/hires/{id}/no-hire

Do not make an offer.

Assume that this ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required