Skip to content
Andreas Fast edited this page Jun 20, 2014 · 4 revisions

What are resources for?

They contain the ruby code to execute for each request. They're the entry point like the controllers in rails.

How do I define a resource?

If adding a 'posts' resource, add a class in resources/posts.rb called Posts that inherits from AngusBase::Resource like this:

class Posts < AngusBase::Resource
  def index
  end
end

Make sure the method name matches the action declared in operations.yml.

How do I access the parameters?

Being a rack based application you can access the elements defined in request and uri by the operations.yml for this action with params[:parameter_key].

For example if you set the path to '/posts/:id' you can access it with params[:id]. It's the same for elements declared inside of request.

The method in the resource needs to return a hash with at least the required keys declared under response for the operation. Take a look at this simple example how the hash returned by the method in the resource matches the definition in operations.yml.