Making Web Playlists URLs better with URL Rewrite module

I have been recently reading about the entire RESTful web services and constantly looking at how we can make our modules more REST friendly in terms of URL look-n-feel and also the output they return (if any). I blogged about RESTful web services in case anyone is interested in knowing more about REST.

At the same time, if you were following Bill's blog, IIS team released URL re-write module. IIS pipeline architecture is such that it almost always requires an extension, URL re-write module helps overcome this limitation. In this post I plan to cover how we can make Web Playlists URLs look prettier (and aligned to REST principles).

Today, Web Playlists URLs are look something like this http://www.example.com/a.isx. For someone looking at this URL and trying to understand, it does mean much. As you have been following my blog all this while ;), you know what isx is (Web Playlists file) but not everyone does. One of the principles of REST as I see applied is that URLs should tell you a lot about what to expect in the response. Let us see how we can live this principle for Web Playlists.

Consider the URLs below

These URLs clearly tell me what to expect as a response. It tells me that response will be a playlist of some kind.

Creating a Rule

Let us take the URL http://example.com/Playlist('a'). In this case the URL tells you that there is a playlist 'a' that this URL refers to. This syntax is very much similar to the Astoria syntax. "Astoria" is the code name for ADO.net Data Services. They are heavily investing in defining URL syntax. Let us see how we can get our existing URLs to look like more like Astoria URLs.

  • We need to first install URL re-writer module. This is an Out of Band module available for free download from http://www.iis.net site: 32-bit and 64-bit. Once you install you will see the Icon for URL re-writer appear in IIS Manager (highlighted below)

image (click to see a larger image)

  • Double-click on the icon and then click "Add Rule...". Then add rule as per image below:

image (click to see a larger image)

  • For the people familiar with IIS configuration files, this creates the following entry in the IIS config file

image (click to see a larger image)

How does this rule work?

If we dissect this rule, "^(.*)/*Playlist\((.*)\)$" pattern says that in URL match everything before "/Playlist" and then match everything in between (). As per the URL re-writer module semantics these will be stored in {R:1} and {R:2} variables which are then used while re-writing the rule. (E.g., in http://example.com/Playlist('a') {R:1} becomes blank and {R:2}becomes a. This is because only URL relative to site root are matched. Thus as per the rule the initial URL will be re-written as http://example.com/a.isx which is understood by the IIS7 pipeline.

Re-cap

In this post I ran through an example of how you could use URL-writer to create friendlier URLs for Web Playlists. I would really like to encourage you to play with URL re-write module to create the other URL form (http://example.com/Playlist/a) and share it as comments to this blog.

I would suggest starting with the walkthroughs here. Happy re-writing and looking forward to your comments.

3 Comments

  • This is a very cool way to apply URL rewrite module! Thanks Vishal for sharing this.

    Is it possible to have a URL with empty parameter? For example: http://example.com/Playlist()

  • Hello A, How do you reverse this module, if you figure this out you could be food, so what is your feed. Insist

  • Hi Ruslan,

    That's a great idea, although in the playlist concept empty URLs won't add much value as there is no way to display a list of playlist today. However, if someone was to create a page that had the capability to list playlists, we could use URL re-write to show a list of playlists availble on the server, this could be a weekend project :)

    Cheers
    Vishal

Comments have been disabled for this content.