4

I'm trying to implement a hypermedia-driven API using Grape mounted directly on top of Rack. Grape supports presenters ("entities") which seem to be the proper place for providing all related hypermedia.

If I had Rails router available, I could simply pick route by its ears and toss it into my presenter logic. For example (ROAR approach):

link :self do
  article_url(self)
end

But Grape itself doesn't provide easy access to routes, as they have no names or aliases akin to article_url.

Has anybody encountered a similar problem with Grape or Sinatra? Is there a clean and simple way of exposing resource links?

dB.
  • 4,700
  • 2
  • 46
  • 51
  • I'm also researching the best way to do this, don't think it's possible with grape though. U could combine webmachine & roar, like [this](https://github.com/apotonick/webmachinelovesroar/blob/master/server.rb) – Yeggeps Nov 02 '12 at 18:55
  • I think this is a worthy feature request to Grape. Feel free to open an issue and elaborate - we could add a set of route helpers like this. – dB. Feb 13 '13 at 18:42

1 Answers1

1

This is possible, but not quite as simply as the Rails url helpers.

From https://github.com/intridea/grape#describing-and-inspecting-an-api:

TwitterAPI::versions # yields [ 'v1', 'v2' ]
TwitterAPI::routes # yields an array of Grape::Route objects
TwitterAPI::routes[0].route_version # yields 'v1'
TwitterAPI::routes[0].route_description # etc.
Robert Pitts
  • 78
  • 1
  • 5