Module: LlmHub::Common::HttpHelper
- Included in:
- ClientBase
- Defined in:
- lib/llm_hub/common/http_helper.rb
Overview
Module to provide HTTP helper methods
Instance Method Summary collapse
-
#http_client(uri) ⇒ Net::HTTP
Return HTTP client based on Uri.
-
#http_post(url, request_body, headers = {}) ⇒ Hash
Call API endpoint for Post.
Instance Method Details
#http_client(uri) ⇒ Net::HTTP
Return HTTP client based on Uri
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/llm_hub/common/http_helper.rb', line 25 def http_client(uri) http_client = Net::HTTP.new( uri.host, uri.port ) http_client.use_ssl = uri.scheme == 'https' http_client.verify_mode = OpenSSL::SSL::VERIFY_NONE http_client.open_timeout = @open_time_out http_client.read_timeout = @read_time_out http_client end |
#http_post(url, request_body, headers = {}) ⇒ Hash
Call API endpoint for Post
13 14 15 16 17 18 19 |
# File 'lib/llm_hub/common/http_helper.rb', line 13 def http_post(url, request_body, headers = {}) # generate uri http uri = URI.parse(url) http = http_client(uri) # http request http.post(uri.path, request_body.to_json, headers) end |