Hyprlinkr icon indicating copy to clipboard operation
Hyprlinkr copied to clipboard

Templates generation

Open andresmoschini opened this issue 9 years ago • 3 comments

Do you think that it is possible to generate link templates or do you have any suggestion about how to extend it to support them?

For example:

var uri = linker.GetUri<FooController>(r => r.GetById(linker.Template("myid")));

to generate

http://localhost/api/foo/{myid}

Or

var uri = linker.GetUri<FooController>(r => r.GetById(linker.Template));

to generate

http://localhost/api/foo/{id}

andresmoschini avatar May 03 '15 12:05 andresmoschini

Does this answer your question?

ploeh avatar May 04 '15 06:05 ploeh

Hehe, yes, it answer my question. Thanks.

Anyway, I think that it would be great to autogenerate the templates or support it for parameters with different types than string.

Thanks again.

andresmoschini avatar May 04 '15 10:05 andresmoschini

It might be valuable to do something like that. To be honest, I never really though much about this, as I found modelling template parameters as strings a fair compromise (since everything that goes into an URL is ultimately a string anyway). However, I can understand if other people would want it with support for stronger types, like e.g. int.

The suggested API might be one way to go about it. It looks reminiscent of Moq's It.IsAny<T>() API.

A proper implementation should use the UriTemplate class for the binding implementation.

ploeh avatar May 04 '15 15:05 ploeh