DPS907 notes – Fri Oct 11

Handling ‘commands’ in a web service. Work on Lab 3 in the lab room T2108.

.

Handling ‘commands’ in a web service

For many weeks, we have been learning to code a web service by thinking of it as an API to a database-like data store. You have learned how to handle the typical CRUD operations (create, retrieve, update, delete) normally associated with data management. The HTTP methods map nicely to these operations, and that familiarity has helped you make progress.

It’s time to expand our thinking, beyond data management. How? By adding the ability to handle commands and operations that may or may not be easily mapped to data management.

In Lab 3, you’ll get a gentle introduction to this concept, by coding commands that feel like commands, but end up changing the (data) state of the targeted resource. This will prepare you for more interesting scenarios in a few weeks.

Assume that you want to do something command-like to a resource. For example, send a representation of the resource by email to a list of pre-configured recipients, and log the action. Or, increase the hourly wage 5% for all employees in a certain department.

There are two ways to look at any of these tasks:

  1. As a command, where we state our intent – ‘do this’ or ‘do that’
  2. As a data management task, where we specifically, technically, and atomically set/update data properties to specific values

Which is the more natural concept to understand? Everyone can understand #1. Only programmers would care enough to understand #2.

How do we map commands to resources?

To preview, we typically send a PUT request to a resource. The underlying method has code that carries out our intent.

CQRS states that a command does something but does not return data to the caller. Therefore, the controller method return type will be void, which automatically creates an HTTP 204 status code. In other words, when handling a ‘command’, we simply execute the command silently, without any data feedback to the requestor (other than the HTTP 204).

.

Work on Lab 3

Work period today. In the lab room. (Not at home. Not in the open lab.)

Work on Lab 3.

I will check your progress during our time together.

I can also help you with any other questions that you may have.

.

.

.

.

.

.

.

.

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: