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?
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.