-
Notifications
You must be signed in to change notification settings - Fork 11
Routing
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:
The name of interface can be substituted in the path:
[Path("api/[facade]")] public interface IEntitiesClient { ... } // the route will be: api/entitiesThe name of the interface will be substituted without prefixes (I) and postfixes (Controller, Client, Facade). Facade token has aliases: [controller] and [client]
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); }