Class: ServiceClient::Base
- Inherits:
-
Object
- Object
- ServiceClient::Base
- Defined in:
- lib/service_client/base.rb
Overview
This class provides a lightweight and flexible way to make HTTP requests in Ruby projects.
This class can be used to make GET, POST, PUT, and DELETE requests to RESTful APIs. It simplifies the HTTP request process with a simple and intuitive API, configurable base URL, and default headers. It also provides a consistent and structured way to receive responses.
Class Method Summary collapse
-
.base_url(url = nil) ⇒ Object
Sets the base URL to be used for all requests.
-
.default_headers(headers = nil) ⇒ Object
Sets the default headers to be sent with all requests.
-
.delete(url = nil, headers: nil) ⇒ Object
Makes a DELETE request to the specified URL.
-
.get(url = nil, headers: nil) ⇒ Object
Makes a GET request to the specified URL.
-
.post(url = nil, headers: nil, body: nil) ⇒ Object
Makes a POST request to the specified URL.
-
.put(url = nil, headers: nil, body: nil) ⇒ Object
Makes a PUT request to the specified URL.
Class Method Details
.base_url(url = nil) ⇒ Object
Sets the base URL to be used for all requests.
25 26 27 |
# File 'lib/service_client/base.rb', line 25 def base_url(url = nil) @base_url = url end |
.default_headers(headers = nil) ⇒ Object
Sets the default headers to be sent with all requests.
32 33 34 |
# File 'lib/service_client/base.rb', line 32 def default_headers(headers = nil) @default_headers = headers end |
.delete(url = nil, headers: nil) ⇒ Object
Makes a DELETE request to the specified URL.
66 67 68 |
# File 'lib/service_client/base.rb', line 66 def delete(url = nil, headers: nil) request(:delete, url, headers: headers) end |
.get(url = nil, headers: nil) ⇒ Object
Makes a GET request to the specified URL.
49 50 51 |
# File 'lib/service_client/base.rb', line 49 def get(url = nil, headers: nil) request(:get, url, headers: headers) end |
.post(url = nil, headers: nil, body: nil) ⇒ Object
Makes a POST request to the specified URL.
41 42 43 |
# File 'lib/service_client/base.rb', line 41 def post(url = nil, headers: nil, body: nil) request(:post, url, headers: headers, body: body) end |
.put(url = nil, headers: nil, body: nil) ⇒ Object
Makes a PUT request to the specified URL.
58 59 60 |
# File 'lib/service_client/base.rb', line 58 def put(url = nil, headers: nil, body: nil) request(:put, url, headers: headers, body: body) end |