Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Uri Templates in v2? #27

Closed
pmcevoy opened this issue Jan 22, 2014 · 6 comments
Closed

Support for Uri Templates in v2? #27

pmcevoy opened this issue Jan 22, 2014 · 6 comments
Labels

Comments

@pmcevoy
Copy link

pmcevoy commented Jan 22, 2014

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?

@ploeh
Copy link
Owner

ploeh commented Jan 22, 2014

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?

@pmcevoy
Copy link
Author

pmcevoy commented Jan 22, 2014

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".

@ploeh
Copy link
Owner

ploeh commented Jan 22, 2014

Yes, but that's just an honest object model; URLs are strings, too ;)

@ploeh
Copy link
Owner

ploeh commented Feb 2, 2014

Does this answer your question?

@pmcevoy
Copy link
Author

pmcevoy commented Feb 3, 2014

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...

@andresmoschini
Copy link

As I commented in #37, I think that it is very useful to accept typed parameters, here you have a quick and dirty implementation:

andresmoschini/hypermedia-api-poc@3381397

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"
    }
  ]
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants