Module: PetstoreApiClient::Request
- Included in:
- Client
- Defined in:
- lib/petstore_api_client/request.rb
Overview
HTTP request methods for the Petstore API client
Provides high-level abstraction over HTTP operations using Faraday. This module implements the Dependency Inversion Principle by abstracting HTTP operations behind a clean interface.
All HTTP methods return a Response object that wraps the Faraday response. Errors are automatically detected and raised as appropriate exception types.
This module is included by Client and provides:
-
GET requests for retrieving resources
-
POST requests for creating resources
-
PUT requests for updating resources
-
DELETE requests for removing resources
Instance Method Summary collapse
-
#delete(path, params: {}) ⇒ Response
Perform HTTP DELETE request.
-
#get(path, params: {}) ⇒ Response
Perform HTTP GET request.
-
#post(path, body: {}) ⇒ Response
Perform HTTP POST request.
-
#put(path, body: {}) ⇒ Response
Perform HTTP PUT request.
Instance Method Details
#delete(path, params: {}) ⇒ Response
Perform HTTP DELETE request
Deletes a resource from the API. Query parameters can be provided via the params hash if needed.
131 132 133 |
# File 'lib/petstore_api_client/request.rb', line 131 def delete(path, params: {}) request(:delete, path, params: params) end |
#get(path, params: {}) ⇒ Response
Perform HTTP GET request
Retrieves a resource from the API. Query parameters can be provided via the params hash.
55 56 57 |
# File 'lib/petstore_api_client/request.rb', line 55 def get(path, params: {}) request(:get, path, params: params) end |
#post(path, body: {}) ⇒ Response
Perform HTTP POST request
Creates a new resource on the API. The request body should contain the resource data as a hash, which will be automatically serialized to JSON.
82 83 84 |
# File 'lib/petstore_api_client/request.rb', line 82 def post(path, body: {}) request(:post, path, body: body) end |
#put(path, body: {}) ⇒ Response
Perform HTTP PUT request
Updates an existing resource on the API. The request body should contain the updated resource data as a hash.
109 110 111 |
# File 'lib/petstore_api_client/request.rb', line 109 def put(path, body: {}) request(:put, path, body: body) end |