Interfaces

Project

Pages Restful

NuGet packageOwin.Framework.Pages.Restful
GitHub sourceOwinFramework.Pages.Restful

Home |  Readme

Service Routing

The [IsService()] attribute has properties that specify how Http requests are routed to the service as folllows.

BasePath

This property of the [IsService()] attribute establishes a route for the service. Any Http requests that match this at the start of their path will be compared to the service endpoints for possible routing to that endpoint. If the base path does not match the Http request then this service is skipped and routing moves onto the next service.

For efficiency you should always specify a base path for each service and organize your service endpoints so that all the endpoints in a serice have the same base path. This arrangement provides the most efficient routing of requests.

If you do not specify a base path then it defaults to / effectively making all of endpoints within the service have absolute paths.

The base path should end with a forward slash because it is concatenated with the relative path of each endpoint to form the full path of the endpoint. If you forget to append a forward slash then one will be appended automatically for you.

The base path can contain wildcards for some path elements but must not end with a wildcard. Since it is designed to match the start of the Http request it will be added to the routing table with ** on the end allowing the endpoints to have any relative path below this base.

Methods

This property of the [IsService()] attribute defines the Http methods that will be routed to the service. If you do not specify the Methods it will default to new []{ Method.Post }. In this case the service will only receive Http POST requests. To handle other kinds of Http request you must set the Methods property.

You can route all Http methods to the service by setting Methods to an empty array like this: new Method[]{ }

Only methods that are routed to the service itself can be further routed to the endpoints within the service with relative paths. Endpoints with absolute paths are chained into the routing at the root level and do not have this restriction.

Priority

This property of the [IsService()] attribute defines the order in which routing will be evaluated. The highest priority routes are considered before the lower priority ones. Since the default priority is zero, the recommentation is to make very specific routes have positive priorities and wildcard routes have negative priority so that the wildcard routes do not mask the more specific routes by matching the request first.

Priorities also affect performance because the router will try to match routes in order or highest to lowest priority until it finds a match. You can make routing more efficient by giving higher priority to routes that are matched more frequently.

Endpoint Routing

Endpoints can have relative or absolute paths. This decision fundamentally changes the routing model for the endpoint.

When endpoints have a relative url path (that does not begin with a forward slash) the endpoint is considered to be within the service and only requests routed to that service can end up at this endpoint.

When endpoints have an absolute url path (that begins with a forward slash) the endpoint is included directly into the root routing table and is indendant of any routing applied to the containing service. In this case there is still advantages in building a service with multiple endpoints because they inherit the settings for serialization, deserialization etc.

The [Endpoint()] attribute has properties that specify how Http requests are routed to the service as folllows.

UrlPath

Specifies the Http path of this endpoint relative to the service BaseUrl property. The endpoint can also specify an absolute path by starting this property value with a forward slash.

If you do not set this property value then the name of the C# method will be used as the relative path.

Methods

For endpoints with an absolute UrlPath this property defines the Http methods that will be routed to this endpoint.

For endpoints with a relative UrlPath this property is a further restriction that is applied after the request is successfully routed to the service. In this case there is no point in adding methods here that are not also in the Methods property of the service.