How to send a form data request with finch

Hello !
I am working with phoenix and trying out finch, which has worked extremely well, until i needed to make a request with a form data type.

I know is not the service, because i can make the request using curl and it responds OK

The request is:

curl --request POST \
  --url \
  --header 'Content-Type: multipart/form-data' \
  --form auth=123abc \
  --form id=1 \
  --form var=foo \

Is it possible to do it with finch, or I need to switch my http client


Yes I think you can do that with Finch. I used it in the past for some project.

You can use to prepare your request. I don’t know if this changed but basically this is how it worked for me :
|> Finch.request(MyFinch)
  • First we have the type of request as an atom.
  • some_url() return the request url as string.
  • some_headers() is a list of tuples. For example [{"Content-Type", "application/json"}, ...]
  • the_body() is the data you want to send. I think it should be iodata. In my case I used a map that is converted to iodata. If I take your curl example it would look like below :
%{auth: "123abc", id: 1, var: "foo"}
|> Jason.encode_to_iodata!()

The response for this request could be {:ok, %Finch.Response{body: body}} or {:error, message}