Comments (7)
Hi @DoCode.
I didn't designed the partial expand to merge such templates.
Why do you need such things?
To me, you should have these templates:
- Example 1:
string uriString = UriTemplate.For("https://localhost:5000/api/resource{?key,value,id,name}")
.WithParameter("id", 10)
.WithPartialExpand()
.ExpandToString();
uriString.ShouldBeEquivalentTo("https://localhost:5000/api/resource?id=10{&key,value,name}");
- Example 2:
string uriString = UriTemplate.For("https://localhost:5000/api/resource?key=mykey&value=myValue{&id,name}")
.WithParameter("id", 10)
.WithPartialExpand()
.ExpandToString();
uriString.ShouldBeEquivalentTo("https://localhost:5000/api/resource?key=mykey&value=myValue&id=10{&name}");
You can see here that the ? operator can be transformed to the & operator automatically if we partially expand a {?a,b,c} query with any of the parameter provided.
from doless.uritemplates.
Hi @letsar,
thanks for your response.
I need such things because I used this in an ASP.NET Core API for HAL links.
The UrlHelper creates the links as a preprocessor for specified routes and after that, your lib expands this strings with RFC6570 templates.
The best would be when the library worked out of the box with the UrlHelper ;-)
from doless.uritemplates.
@DoCode thanks for this explanation. So if I understand correctly the UrlHelper
creates url like "https://localhost:5000/api/resource{?key,value}{?id,name}"
?
from doless.uritemplates.
@letsar sorry for the delay.
No, I generate the links first, with the UrlHelper, based on the current request/response and then append the RFC6570 template parts with your libs.
from doless.uritemplates.
Ok so you generate the part {?key,value}{?id,name}
? Why don't you generate {?key,value,id,name}
instead ?
from doless.uritemplates.
The problem is, that I don't know if the existing (pre-rendered via UrlHelper) already contains a query.
Like this code snippet:
protected override Task EnrichModel(INameBaseModel content, IUrlHelper urlHelper)
{
RouteValueDictionary routeData = urlHelper.GetRouteDataWithQuery();
...
new Link(
HttpActionVerb.PUT,
UriTemplate.For(urlHelper.Link(urlHelper.ActionContext.ActionDescriptor.AttributeRouteInfo.Name, routeData) + "{&value}")
.WithPartialExpand()
.ExpandToString(),
RelationType.Self
);
...
}
from doless.uritemplates.
Ok I understand now.
UriTemplate must be a valid uri in the first place, so you will have to handle it yourself. If you want you can do that with an extension method and submit a pull request, so that it will be available for other people.
from doless.uritemplates.
Related Issues (2)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from doless.uritemplates.