Class: ElasticGraph::GraphQL::HTTPResponse

Inherits:
Data
  • Object
show all
Defined in:
lib/elastic_graph/graphql/http_endpoint.rb

Overview

Represents an HTTP response, containing:

  • status_code: an integer like 200.

  • headers: a hash with string keys and values containing HTTP response headers.

  • body: a string containing the response body.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body

Returns:

  • (Object)

    the current value of body



213
214
215
# File 'lib/elastic_graph/graphql/http_endpoint.rb', line 213

def body
  @body
end

#headersObject (readonly)

Returns the value of attribute headers

Returns:

  • (Object)

    the current value of headers



213
214
215
# File 'lib/elastic_graph/graphql/http_endpoint.rb', line 213

def headers
  @headers
end

#status_codeObject (readonly)

Returns the value of attribute status_code

Returns:

  • (Object)

    the current value of status_code



213
214
215
# File 'lib/elastic_graph/graphql/http_endpoint.rb', line 213

def status_code
  @status_code
end

Class Method Details

.error(status_code, message) ⇒ Object

Helper method for building an error response.



222
223
224
# File 'lib/elastic_graph/graphql/http_endpoint.rb', line 222

def self.error(status_code, message)
  json(status_code, {"errors" => [{"message" => message}]})
end

.json(status_code, body) ⇒ Object

Helper method for building a JSON response.



217
218
219
# File 'lib/elastic_graph/graphql/http_endpoint.rb', line 217

def self.json(status_code, body)
  new(status_code, {"Content-Type" => HTTPEndpoint::APPLICATION_JSON}, ::JSON.generate(body))
end