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

Adding RFC6570 style uri templates to store - issue 275 #328

Closed

Conversation

PaulAYoung
Copy link

Changes the uri templates in store to match RFC6570.

Fixes #275.

@tilgovi
Copy link
Member

tilgovi commented Mar 20, 2014

Looks cool. @nickstenning how do you feel about something like this?

Worth doing? Breaks compatibility. But interesting to me because an RFC is nice to have as a reference when pursuing bootstrapping the store automatically, given that annotator-store already publishes an API discovery document.

@nickstenning
Copy link
Member

I think this is breakage worth having.

P.S. This is an example of why the browserify work was worth doing!

@nickstenning
Copy link
Member

Ah, although there is a slight subtlety here. The existing implementation has a slightly kooky behaviour for the read URL, namely /annotation/:id will expand to /annotation/123 if an ID is provided, but /annotation (note the lack of trailing slash) if not. I'm surprised we don't have tests for that.

The point here is that if you don't specify loadFromSearch, then the return value of _urlFor('read') is used as the endpoint from which to retrieve annotations, and this PR will change the default requested URL from /store/annotations to /store/annotations/.

@nickstenning
Copy link
Member

And just to be clear, I'm not defending the current behaviour -- merely raising an issue that might want to be considered before we merge this.

@nickstenning
Copy link
Member

So, I'm totally keen on making this work, and making the new standard URL definitions RFC6570-compliant. In order to ship this in 2.0, however, I'd like us to provide backwards compatibility for the old style, and issue a deprecation warning.

Perhaps the best way of doing this would be to try parsing the provided URLs with the RFC-compliant parser, and then inspect the templates. If they don't have the right fields (i.e. one for id), then we fall back to the old way, issuing a Util.deprecationWarning(...) along the way.

@nickstenning
Copy link
Member

You may also wish to make sure you're aware of what will (hopefully) soon be merged in #361 before updating this PR.

# If there's a bare ':id' in the URL, then substitute directly:
url = url.replace(/:id/, if id? then id else '')
t_url = template.parse(url)
t_url.expand({id: id})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tiny style comment, the project uses camel case for variable and method names (t_url -> tUrl).

@aron
Copy link
Contributor

aron commented Apr 14, 2014

Also think this is a great idea.

Just wanted to question the use of adding a 1kb (gzipped) dependency to replace two regular expressions. I think it's totally warranted if the library is going to be used in multiple places across the project but if it's just here then surely it would make more sense to just update the RegExp?

It can still be RFC compliant but will keep the number of external dependencies down and the code easy to follow.

@tilgovi
Copy link
Member

tilgovi commented Sep 22, 2014

@nickstenning you closed the issue, but this PR is open. FWIW I'm still in favor of heading this direction, I think... though I'm curious what @BigBlueHat thinks since I know he's been playing with RAML and likes to think about schemas and descriptors and whatnot.

@BigBlueHat
Copy link
Contributor

@tilgovi no idea how I missed your mention in September...

Regardless, huge 👍 for this change (thanks for merging it @nickstenning), and another 👍 for pursuing more document / definition centric development, documentation, and deliverables. 😸

/me goes back to hunting down his RAML work for Annotator...

@BigBlueHat
Copy link
Contributor

Found it! hypothesis/h#1516

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

Successfully merging this pull request may close these issues.

Use RFC6570 URI Templates in Store Configuration
5 participants