beto

beto

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 https:domain.com \
  --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

Thanks!

Most Liked

Kurisu

Kurisu

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

You can use Finch.build to prepare your request. I don’t know if this changed but basically this is how it worked for me :

Finch.build(
        :post,
        some_url(),
        some_headers(),
        the_body()
      )
|> 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!()

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

Where Next?

Popular in Questions Top

Tee
can someone please explain to me how Enum.reduce works with maps
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
sacepums
Hey guys. I'm new to elixir and im really stocked about it. But I ran into a bit of problem - I need to convert a date sting, for examp...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
gonzofish
I’m currently trying to understand how to join three tables using Ecto. All the examples I’ve seen use 2, so maybe I’m just missing somet...
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
sabri
Can someone explain the settings of pool_size of Ecto in config file? and what is the recommend size? Thanks
New
idi527
I’ve been re-reading swift book again and noticed that multiline strings there don’t have a trailing line break, unlike in elixir iex(2)...
New

Other popular topics Top

sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
977 41022 311
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 49522 488
New
danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 27727 240
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
magnetic
Hey :wave:t3: Elixir community, I’ve been learning Elixir, and working on some side projects. My editor of choice is VSCode, and althoug...
New

We're in Beta

About us Mission Statement