lostisland / sawyer

Secret User Agent of HTTP
MIT License
247 stars 75 forks source link

Fix #head and #get helpers on Relation using the default method #27

Closed eduardog closed 5 years ago

eduardog commented 10 years ago

Specifying the method to #call without a body is ambiguous, so that method's documentation has been updated to reflect actual behavior.

A user could theoretically set up a Relation with a default method of POST for an endpoint that expects a method value in a body being serialized from a hash. I'm not sure there's a way to differentiate that case from someone trying to specify a body-less method type in the options hash that doesn't violate the principle of least surprise in at least some cases.

technoweenie commented 5 years ago

Thanks for your feedback and PR, but I don't see where the problem is. You should be able to call such a request like this:

rel.call({ method: "API" }, { method: "POST" })

# looks better on multiple lines IMO
body = { 
  method: "API",
  a: "b",
}
rel.call(body, method: "POST")