I'm trying to set up a rom-http relation for basic REST CRUD, but I find the documentation to be pretty scarce for a beginner, and a little too complex when digging in. What I've tried so far is this:
rom = ROM.container(:http, uri: 'http://localhost:8000', handlers: :json) do |conf|
conf.relation(:users) do
schema(:users) do
end
end
end
This queries the URI http://localhost:8000/users, but how do I configure prefixes, parameters and related resources?
What I'd like to accomplish is being able to consume a URI such as http://localhost:8000/users/1/posts?start=0&size=10 where we have
- a global prefix (
api
) - a version prefix (
v1
, could be part of the global prefix) - a parent resource (
users/1
) - a child resource (
posts
) - query parameters (bonus points if they can be chained like
.offset(0).limit(10)
)
Is this possible with the current implementation? The documentation could use a deeper example, without forcing newcomers to dig into the architecture - which is without doubt brilliant, but complex for someone coming from the ease of use (and the pitfalls) of ActiveRecord. :-)
Sorry that nobody has replied to this yet, the current built-in json handler is a bit broken at the moment, it builds the uri manually when it should just use it from the dataset, you can achieve what you want with something like the following:
NOTE: I only called
.dataset.uri
to show an example of the URI that would be queried, as I don't have a compatible API running locally.NOTE: For anything beyond playing around with the library, you'll probably want to use a custom adapter anyway.
Also, for nested resources, ROM can query those automatically, check the (out-dated) example sections below to see how that works.