class Served::Backends::HTTP

HTTP Backend uses {github.com/httprb/http HTTP} client library.

Public Instance Methods

delete(endpoint, id, params = {}) click to toggle source
# File lib/served/backends/http.rb, line 41
def delete(endpoint, id, params = {})
  response = ::HTTP
    .timeout(global: timeout)
    .headers(headers)
    .delete(template.expand(query:    params,
                            resource: endpoint,
                            id:       id).to_s)
  serialize_response(response)
rescue ::HTTP::ConnectionError
  raise Served::HTTPClient::ConnectionFailed.new(resource)
end
get(endpoint, id, params = {}) click to toggle source
# File lib/served/backends/http.rb, line 6
def get(endpoint, id, params = {})
  response = ::HTTP
    .timeout(global: timeout)
    .headers(headers)
    .get(template.expand(id: id, query: params, resource: endpoint).to_s)
  serialize_response(response)
rescue ::HTTP::ConnectionError
  raise Served::HTTPClient::ConnectionFailed.new(resource)
end
post(endpoint, body, params = {}) click to toggle source
# File lib/served/backends/http.rb, line 29
def post(endpoint, body, params = {})
  response = ::HTTP
    .timeout(global: timeout)
    .headers(headers)
    .post(template.expand(query:    params,
                          resource: endpoint).to_s,
          body: body)
  serialize_response(response)
rescue ::HTTP::ConnectionError
  raise Served::HTTPClient::ConnectionFailed.new(resource)
end
put(endpoint, id, body, params = {}) click to toggle source
# File lib/served/backends/http.rb, line 16
def put(endpoint, id, body, params = {})
  response = ::HTTP
    .timeout(global: timeout)
    .headers(headers)
    .put(template.expand(id:       id,
                         query:    params,
                         resource: endpoint).to_s,
         body: body)
  serialize_response(response)
rescue ::HTTP::ConnectionError
  raise Served::HTTPClient::ConnectionFailed.new(resource)
end