Closed pmcevoy closed 10 years ago
I usually do this:
Assume a SearchController
with a Get
method:
public HttpResponseMessage Get(string q)
In order to create a template from this, I do this:
Href = this.linker.GetUri<SearchController>(c =>
c.Get("{query}")).ToString()
This automatically produces a URL like http://foo.com/search?q={query}
.
Would that be usable, or do you need something more than that?
I can certainly give it a go and see how far it gets me... although that looks like all controller method params would then need to be "string".
Yes, but that's just an honest object model; URLs are strings, too ;)
Does this answer your question?
Sorry for not closing. Would be great if it was able to introspect and auto generate, but for now this digs me out of a hole...
As I commented in #37, I think that it is very useful to accept typed parameters, here you have a quick and dirty implementation:
https://github.com/andresmoschini/hypermedia-api-poc/commit/3381397fab6375064e0dd18659cc90f917a11af6
The result is the follow:
{
"links": [
{
"href": "/",
"rel": "self home"
},
{
"href": "/accounts",
"rel": "account-collection",
"description": "Account List"
},
{
"href": "/accounts/128",
"rel": "account-item",
"description": "My account details"
},
{
"href": "/accounts/{accountId}",
"rel": "account-item",
"description": "Other accounts"
},
{
"href": "/accounts/{miPersonalizedText}",
"rel": "account-item",
"description": "Other accounts"
}
]
}
I realize that features for hyprlinkr are now fixed, so perhaps you could consider adding support for generating Uri Templates (ala http://tools.ietf.org/html/rfc6570) in v-next?