Skip to content

Latest commit

 

History

History
22 lines (17 loc) · 815 Bytes

empty-body-handling.md

File metadata and controls

22 lines (17 loc) · 815 Bytes

Flexirest: Empty body handling

If you call a RESTful method that correctly returns a 204 when the request was accepted, but no body is supplied, Flexirest will return true. If you call this on an instance of a Flexirest subclass, it will not affect the existing attributes.

class Person < Flexirest::Base
  put :save, "/people/:id"
end

p = Person.new(id: "1", name: "Jenny")
saved = p.save
puts saved === true # true
puts p.name # Jenny

If your API returns a 200 OK status with an empty body, by default this is handled in the normal way - the attributes are set to an empty set. If you intend to handle it as above for the 204, you can set an extra option on the mapped method like this:

class Person < Flexirest::Base
  put :save, "/people/:id", ignore_empty_response: true
end