jpbochi / halberd

JavaScript implementation of HAL format
Other
8 stars 3 forks source link

Add support for CURIES #2

Open nareshbhatia opened 10 years ago

nareshbhatia commented 10 years ago

Add support for CURIES. See HAL specification: http://tools.ietf.org/pdf/draft-kelly-json-hal-06.pdf. Also see clarification here: https://groups.google.com/forum/#!topic/hal-discuss/1ZpslQ2GmG0

jpbochi commented 10 years ago

@nareshbhatia I was thinking about how to implement this.

I'd need something to join http://haltalk.herokuapp.com/docs/{rel} and /posts/latest into http://haltalk.herokuapp.com/docs/posts/latest. I guess there are some hidden rules there. A simple replace would create two slashes between docs and posts. Are you using any link templating library? Do you have any to suggest? It might be a good idea to use it here instead of building something from scratch.

jpbochi commented 10 years ago

https://www.npmjs.org/package/uritemplate looks good, and has no dependencies.

jpbochi commented 10 years ago

That's interesting.

> require('uritemplate').parse('http://haltalk.herokuapp.com/docs/{rel}').expand({ rel: '/some/where' })
'http://haltalk.herokuapp.com/docs/%2Fsome%2Fwhere'
> require('uritemplate').parse('http://haltalk.herokuapp.com/docs/{+rel}').expand({ rel: '/some/where' })
'http://haltalk.herokuapp.com/docs//some/where'
jpbochi commented 10 years ago

Tested with https://www.npmjs.org/package/uri-template, too and it does the same thing.

And apparently, they are correct. See http://tools.ietf.org/html/rfc6570#section-3.2.3

jpbochi commented 10 years ago

Started a thread on hal-discuss. https://groups.google.com/forum/#!topic/hal-discuss/3hwoWts4GkQ