The Telligent Evolution platform SDK 5.5.2 provides two examples of creating custom REST routes: one that uses a custom handler for performing functionality outside of the basic REST spectrum and another that uses the standard Telligent Evolution REST pipeline - RestRouteHandler and RestHttpHandler - for handling REST requests. Both of these examples of custom routing can be found in projects in the platform SDK.

Registering custom REST routes is done by creating a route registrar class that implements IRegisterRoutes or inherits from the BaseRouteRegistrar (which implements IRegisterRoutes itself). After your class is created, you need to add a mapping to it in the RestModule.config file contained in your Web site's Modules folder.

Routing with custom handlers

The Telligent.Rest.Console project in the SDK provides an example of adding a route to your site to perform a custom activity that does not use the standard RestHttpHandler. In this case it displays the REST console. Take a look at the ConsoleRouteRegistrar class - it only has one method, an override of RegisterRoutes, that simply adds a route to the JavaScript-based console to the RouteTable. Rather than using the passed in IRouteHandler (which is in fact the RestRouteHandler), it instead creates an instance of its own IRouteHandler and IHttpHandler, ConsoleRouteHandler, and ConsoleHttpHandler. You can review the code for both of those files to see how the ConsoleRouteHandler creates and returns the ConsoleHttpHandler and what the ConsoleHttpHandler does with the HTTP request.

Routing with default REST handlers

The CustomEndpoint project in the platform SDK provides an end-to-end example of creating a custom REST endpoint from routes to controllers to actions. The FooRouteRegister class is an example of using the default pipeline, RestRouteHandler and RestHttpHandler, for basic REST functionality.

Like the example from the console application, FooRouteRegistrar inherits from BaseRouteRegistrar and overrides the base class' RegisterRoutes method. That is where all similarities end. The FooRouteRegistrar registers routes for LIST, SHOW, CREATE, UPDATE, and DELETE actions for the Foo controller. The RegisterRoutes method makes use of a helper method of the base class, Register, that provides a shortcut for registering routes. This class provides a thorough example of many different scenarios you will face when creating/registering your routes, including defining the resource and actions, setting constraints, and adding comments.

Mapping IRegisterRoutes to your custom route registrar

Once you've finished creating your custom route registrar, you'll need to let the system know that your assembly contains custom REST routing information. You do that by adding an entry to the RestModule.config file that maps CommunityServer.Rest.Infrastructure.IRegisterRoutes to your class. See the existing entry for the Telligent.Rest.Console.ConsoleRouteRegistrar in your RestModule.config file for an example.

Add the mapping and drop your custom assembly into your Web site's bin folder.

You may need to restart your site (IIS restart, stop/start the site, or bump the web.config file) before your routing changes have an effect.

If you are using the REST console, you can view your routes in the route drop-down list. Click the Get button beside the route drop-down list and the list will then be filled with all the routes that have been registered. Routes are listed alphabetically by the resource name. You should be able to scroll down and see your new routes.