Url Helper Policy Expressions for Route Building
As a developer I want to include hypermedia links to other operations in the same and other API sets so that I have easy navigation for clients between APIs.
Today, these link url paths must be hard coded based on what is know. To provide flexibility while developing APIs and to ensure routes are actually valid, provide a url helper method to generate these routes.
Example:
context.RouteFor("API-ID", "Version", "Operation-ID", new {param1=1,param2="hello"})
Today:
<set-body>{
return JObject.FromObject(new {
_links = new[] {
new { href = $"/api/operation?query={context.Request.MatchedParameters.GetValueOrDefault("query", string.Empty)&api-version=2018-10-31", rel = "other-api", type = "GET" }
}
}
}</set-body>
With a helper:
<set-body>{
return JObject.FromObject(new {
_links = new[] {
new { href = context.RouteFor("api", "2018-10-31", "operation", new { query = context.Request.MatchedParameters.GetValueOrDefault("query", string.Empty) }), rel = "other-api", type = "GET" }
}
}
}</set-body>
The helper should throw an error if the route does not exist at run-time.