Module: WebFetch::ClientHttp
- Included in:
- Client
- Defined in:
- lib/web_fetch/concerns/client_http.rb
Instance Method Summary collapse
Instance Method Details
#base_uri ⇒ Object
5 6 7 |
# File 'lib/web_fetch/concerns/client_http.rb', line 5 def base_uri "http://#{@host}:#{@port}" end |
#get(endpoint, params = {}) ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'lib/web_fetch/concerns/client_http.rb', line 9 def get(endpoint, params = {}) conn = Faraday.new(url: base_uri) conn.get do |request| request.url "/#{endpoint}" request.params.merge!(params) end rescue Faraday::ConnectionFailed => e raise ClientError, e. end |
#post(endpoint, body) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/web_fetch/concerns/client_http.rb', line 19 def post(endpoint, body) conn = Faraday.new(url: base_uri) conn.post do |request| request.url "/#{endpoint}" request.body = body end rescue Faraday::ConnectionFailed => e raise ClientError, e. end |