DPS907 notes – Thu Oct 9

Attribute based routing. Exception handling, version 2. Work on Lab 5.

.

Attribute based routing

In the previous class session, we introduced attribute based routing.

This feature is ‘on’ by default in our projects. We can use it in combination with the existing convention based routing.

This article by Mike Wasson (on the official ASP.NET Web API web site) fully explains attribute routing. Read it, and begin using the feature in your work.

.

Improving the “Images” code example

The originally-posted “Images” code example did not include link relations for its new functionality.

In other words, there was no way for a requestor to ‘discover’ that a photo representation was available. Or how to set/configure a photo for a book object.

As a result, your professor’s “version 1” solution was implemented and re-posted to the code example GitHub repository.

.

Fix #1 – edit the Link class (in Links_vm.cs)

Three more string properties were added to the Link class:

  • ContentType
  • Method
  • Title

Read the code comments to learn their purpose and usage.

.

Fix #2 – edit the ‘get one’ method in the BooksController class

Two more Link objects were created and added to the packaging container’s Links collection:

  • one link tells the requestor that a ‘photo’ representation is available
  • the other link tells the requestor how to set/configure a photo for the resource

.

There may be other methods for which additional links would be useful. Think about this topic, and implement where appropriate.

Enjoy. If you can think of improvements, please contribute them.

.

Handling exceptions, again

Today’s code example, “ErrorHandling”, introduces you to a good way to handle and log general exceptions in your app.

You would add this capability part-way through your development, so that you can effectively test.

Inspiration for this topic was taken from the Exception Handling in ASP.NET Web API article.

.

Work on Lab 5

Time permitting, you can work on Lab 5.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

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: