Module: Wurk::API::Response
- Defined in:
- lib/wurk/api/response.rb
Overview
Success bodies for the HTTP API; Problem is the error half. One owner per content type the API emits, so a route table never spells out a header for itself and the two halves can't drift on the ones they share.
Constant Summary collapse
- CONTENT_TYPE =
'application/json'- HEADERS =
nosniff for Problem's reason: a body that echoes what the client sent must never be talked into rendering as anything but data.
{ 'content-type' => CONTENT_TYPE, 'x-content-type-options' => 'nosniff' }.freeze
Class Method Summary collapse
-
.json(status, payload) ⇒ Array(Integer, Hash, Array<String>)
Dups the headers because a Rack middleware downstream is entitled to add to them, and the frozen literal is shared by every response.
Class Method Details
.json(status, payload) ⇒ Array(Integer, Hash, Array<String>)
Dups the headers because a Rack middleware downstream is entitled to add to them, and the frozen literal is shared by every response.
23 24 25 |
# File 'lib/wurk/api/response.rb', line 23 def json(status, payload) [status, HEADERS.dup, [::JSON.generate(payload)]] end |