class Halite::Response
- Halite::Response
 - Reference
 - Object
 
Defined in:
halite/response.crConstructors
- .new(uri : URI, status_code : Int32, body : String? = nil, headers = HTTP::Headers.new, status_message = nil, body_io : IO? = nil, version = "HTTP/1.1", history = [] of Halite::Response)
 - .new(uri : URI, conn : HTTP::Client::Response, history = [] of Halite::Response)
 
Instance Method Summary
- #body(*args, **options)
 - #body(*args, **options, &)
 - #body_io(*args, **options)
 - #body_io(*args, **options, &)
 - #charset(*args, **options)
 - #charset(*args, **options, &)
 - #conn : HTTP::Client::Response
 - 
        #content_length : Int64?
        
          
Content Length
 - #content_type(*args, **options)
 - #content_type(*args, **options, &)
 - 
        #cookies : HTTP::Cookies?
        
          
Return a
HTTP::Cookiesof parsed cookie headers or else nil. - 
        #filename : String?
        
          
Return filename if it exists, else
Nil. - #headers(*args, **options)
 - #headers(*args, **options, &)
 - #history : Array(Response)
 - 
        #inspect
        
          
Returns a
Stringrepresentation of this object suitable to be embedded inside other expressions, sometimes providing more information about this object. - 
        #links : Hash(String, Halite::HeaderLink)?
        
          
Return a list of parsed link headers proxies or else nil.
 - 
        #parse(name : String? = nil)
        
          
Parse response body with corresponding MIME type adapter.
 - 
        #raise_for_status
        
          
Raise
Halite::ClientError/Halite::ServerErrorif one occurred. - #rate_limit : Halite::RateLimit?
 - #status_code(*args, **options)
 - #status_code(*args, **options, &)
 - #status_message(*args, **options)
 - #status_message(*args, **options, &)
 - #success?(*args, **options)
 - #success?(*args, **options, &)
 - 
        #to_a
        
          
Return status_code, headers and body in a array
 - 
        #to_raw
        
          
Return raw of response
 - #to_s(io)
 - 
        #to_s
        
          
Return String eagerly consume the entire body as a string
 - #uri : URI
 - #version(*args, **options)
 - #version(*args, **options, &)
 
Constructor Detail
Instance Method Detail
Returns a String representation of this object suitable
to be embedded inside other expressions, sometimes providing
more information about this object.
#inspect (and #inspect(io)) are the methods used when
you invoke #to_s or #inspect on an object that holds
other objects and wants to show them. For example when you
invoke Array#to_s, #inspect will be invoked on each element:
ary = ["one", "two", "three, etc."]
ary.inspect # => ["one", "two", "three, etc."]
Note that if Array invoked #to_s on each of the elements
above, the output would have been this:
ary = ["one", "two", "three, etc."]
# If inspect invoked to_s on each element...
ary.inspect # => [one, two, three, etc.]
Note that it's not clear how many elements the array has,
or which are they, because #to_s doesn't guarantee that
the string representation is clearly delimited (in the case
of String the quotes are not shown).
Also note that sometimes the output of #inspect will look
like a Crystal expression that will compile, but this isn't
always the case, nor is it necessary. Notably, Reference#inspect
and Struct#inspect return values that don't compile.
Classes must usually not override this method. Instead,
they must override inspect(io), which must append to the
given IO object.
Return a list of parsed link headers proxies or else nil.
Raise Halite::ClientError/Halite::ServerError if one occurred.
4XXraise anHalite::ClientErrorexception5XXraise anHalite::ServerErrorexception- return 
nilwith other status code 
Halite.get("https://httpbin.org/status/404").raise_for_status
# => Unhandled exception: 404 not found error with url: https://httpbin.org/status/404  (Halite::ClientError)
Halite.get("https://httpbin.org/status/500", params: {"foo" => "bar"}).raise_for_status
# => Unhandled exception: 500 internal server error error with url: https://httpbin.org/status/500?foo=bar  (Halite::ServerError)
Halite.get("https://httpbin.org/status/301").raise_for_status
# => nil