Class: SpecForge::HTTP::Request
- Inherits:
-
Struct
- Object
- Struct
- SpecForge::HTTP::Request
- Defined in:
- lib/spec_forge/http/request.rb
Overview
Represents an HTTP request with all its components
Request is a value object that holds the URL, method, headers, query parameters, and body for an HTTP request.
Instance Attribute Summary collapse
-
#base_url ⇒ Object
Returns the value of attribute base_url.
-
#body ⇒ Object
Returns the value of attribute body.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#http_verb ⇒ Object
Returns the value of attribute http_verb.
-
#query ⇒ Object
Returns the value of attribute query.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
-
#content_type ⇒ String?
Returns the Content-Type header value.
-
#initialize(**options) ⇒ Request
constructor
Creates a new HTTP request with the specified options.
-
#json? ⇒ Boolean
Returns whether this request has a JSON content type.
-
#to_h ⇒ Hash
Converts the request to a hash with stringified verb.
Constructor Details
#initialize(**options) ⇒ Request
Creates a new HTTP request with the specified options
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/spec_forge/http/request.rb', line 25 def initialize(**) super( base_url: [:base_url] || "", url: [:url] || "", http_verb: Verb.from([:http_verb].presence || "GET"), headers: [:headers] || {}, query: [:query] || {}, body: [:body] || {} ) end |
Instance Attribute Details
#base_url ⇒ Object
Returns the value of attribute base_url
11 12 13 |
# File 'lib/spec_forge/http/request.rb', line 11 def base_url @base_url end |
#body ⇒ Object
Returns the value of attribute body
11 12 13 |
# File 'lib/spec_forge/http/request.rb', line 11 def body @body end |
#headers ⇒ Object
Returns the value of attribute headers
11 12 13 |
# File 'lib/spec_forge/http/request.rb', line 11 def headers @headers end |
#http_verb ⇒ Object
Returns the value of attribute http_verb
11 12 13 |
# File 'lib/spec_forge/http/request.rb', line 11 def http_verb @http_verb end |
#query ⇒ Object
Returns the value of attribute query
11 12 13 |
# File 'lib/spec_forge/http/request.rb', line 11 def query @query end |
#url ⇒ Object
Returns the value of attribute url
11 12 13 |
# File 'lib/spec_forge/http/request.rb', line 11 def url @url end |
Instance Method Details
#content_type ⇒ String?
Returns the Content-Type header value
41 42 43 |
# File 'lib/spec_forge/http/request.rb', line 41 def content_type headers["content-type"] end |
#json? ⇒ Boolean
Returns whether this request has a JSON content type
50 51 52 |
# File 'lib/spec_forge/http/request.rb', line 50 def json? content_type == "application/json" end |
#to_h ⇒ Hash
Converts the request to a hash with stringified verb
59 60 61 62 63 |
# File 'lib/spec_forge/http/request.rb', line 59 def to_h super.tap do |h| h[:http_verb] = h[:http_verb].to_s end end |