mamantoha / crest

HTTP and REST client for Crystal
https://mamantoha.github.io/crest/
MIT License
235 stars 14 forks source link

Support passing IO to request #175

Closed cyangle closed 2 years ago

cyangle commented 2 years ago

Currently, below code raises exception:

Crest.post(
  "http://httpbin.org/post",
  File.open("avatar.png"),
  headers: {"Content-Type" => "image/png"}
)

Exception:

In src/crest/request.cr:125:7

 125 | generate_form_data!(form) if form
       ^------------------
Error: no overload matches 'Crest::Request#generate_form_data!' with type File

Overloads are:
 - Crest::Request#generate_form_data!(form : Hash)
 - Crest::Request#generate_form_data!(form : String)

It seems to be trivial to support it, see code in https://github.com/cyangle/crest/tree/support_io_as_form_data

@mamantoha

mamantoha commented 2 years ago

Hi @cyangle . Please add specs and I will merge.