| Class | Relax::Service |
| In: |
lib/relax/service.rb
|
| Parent: | Object |
Service is the starting point for any REST consumer written with Relax. It is responsible for setting up the endpoint for the service, and issuing the HTTP requests for each call made.
When writing consumers, you should start by extending Service by inheriting from it and calling its constructor with the endpoint for the service.
class Service < Relax::Service
ENDPOINT = 'http://example.com/services/rest/'
def initialize
super(ENDPOINT)
end
end
Each call made to the service goes through the call method of Service, which takes in a Request object and a Response class. The Request object is used to generate the query string that will be passed to the endpoint. The Reponse class is instantiated with the body of the response from the HTTP request.
This example show how to create a barebones call. This module can be then included into your Service class.
module Search
class SearchRequest < Relax::Request
end
class SearchResponse < Relax::Response
end
def search(options = {})
call(SearchRequest.new(options), SearchResponse)
end
end
| endpoint | [R] |
This constructor should be called from your Service with the endpoint URL for the REST service.
Calls the service using a query built from the Request object passed in as its first parameter. Once the response comes back from the service, the body of the response is used to instantiate the response class, and this response object is returned.