Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Routing

Stanislav Molchanovskiy edited this page Nov 15, 2021 · 2 revisions

To generate the path to the endpoint, the client has support for route templates as in ASP.NET. Route templates are passed to the following attributes: PathAttribute, QueryParamAttribute, BodyParamAttribute, HeaderParamAttribute, RouteParamAttribute. The PathAttribute sets the base path for all interface methods, the other attributes set the relative path to a specific endpoint.

Routes can contain two types of tokens that are inserted into the path in runtime:

Facade token

The name of interface can be substituted in the path:

[Path("api/[facade]")] public interface IEntitiesClient { ... } // the route will be: api/entities

The name of the interface will be substituted without prefixes (I) and postfixes (Controller, Client, Facade). Facade token has aliases: [controller] and [client]

Parameter token

Method parameters can be completely substituted in the path:

public interface IMyClient { [GetMethod("entities/{id}")] Entity[] Get(int id); }

If a complex object is passed as a parameter, you can insert its property into the path:

public interface IMyClient { [PutMethod("entities/{entity.Id}")] void Put(Entity entity); }
Clone this wiki locally