Can "Handy-URI-Templates" expand URIs partially? #24

Closed
martinicr opened this Issue Feb 12, 2015 · 8 comments

Projects

None yet

5 participants

@martinicr

Hi guys, first of all, I love "Handy-URI-Templates" library, works awesome. Now this not exactly an issue, is more a question about a feature.

I have this URI template:
http://localhost/my-app/employees{/employeeId}/reviews{?page,size}

I would like to provide the "employeeId" variable to the template BUT keep the {?page,size} section. Something like:
http://localhost/my-app/employees/999/reviews{?page,size}

I know the expand() method will hide unused variables in the template and also I know what I'm trying to do is probably not aligned with RFC 6570 but, is there a way to achieve this by using "Handy-URI-Templates"?

Thanks,

Martin.

@damnhandy
Owner

It took me a while to grok what you're saying, but what you are looking for is that rather than the expansion return an expanded URI, you want it to return a new template with the partial values filled in?

@damnhandy
Owner

It would be possible to add an expandPartial() method that would return another URITemplate instance. If that's what you're after, let me know. It'd be trivial to add.

@damnhandy damnhandy self-assigned this Mar 1, 2015
@martinicr

Hi thank your for taking for time on this (and sorry for the late response). I think you got the idea behind this kind of new "feature".

My idea behind the expandPartial() method could be something like:
Scenario #1
Given I have a URI template with format:
http://api.company.com/resources{/resourceId}{?page,size}
When I ask for a partial expansion with resourceId = 999
Then I should have a String like:
http://api.company.com/resources/999{?page,size}

Scenario #2
Given I have a URI template with format:
http://api.company.com/resources{/resourceId}{?page,size}
When I ask for a partial expansion with
page = 0 and
size = 10
Then I should have a String like:
http://api.company.com/resources{/resourceId}?page=0&size=10

Scenario #3
Given I have a URI template with format:
http://api.company.com/resources{/resourceId}{?page,size}
When I ask for a partial expansion with
resourceId = 999
page = 0 and
size = 10
Then I should have a String like:
http://api.company.com/resources/999?page=0&size=10

@drdamour

+1

@Vulcannis

+1

@damnhandy damnhandy added this to the 2.0.3 milestone Sep 4, 2015
@damnhandy
Owner

Thanks to Pull request #28 , we now have this feature. I have published a snapshot of 2.0.3 which contains this PR. If folks could test that and verify it's working as you've anticipated, I'll cut a release. At the moment, I'm planning in doing that tonight anyway.

@damnhandy damnhandy closed this Sep 5, 2015
@stefanseifert
Contributor

i'm a colleague of cnagel (#28) - he is out of office this week.
we tested the latest 2.0.3-SNAPSHOT and it looks fine - thanks for the quick merge!

@damnhandy
Owner

Thanks! I'm trying to push out the release, but it seems the github pages maven plugin I'm using is having some issues. Once I get that sorted out, I'll release 2.0.3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment