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
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 asstring. -
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 beiodata. In my case I used a map that is converted toiodata. 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}
1
Popular in Questions
can someone please explain to me how Enum.reduce works with maps
New
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
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
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
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
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
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
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
Can someone explain the settings of pool_size of Ecto in config file? and what is the recommend size?
Thanks
New
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
Hello!
tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability.
After spen...
New
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
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
Hi folks,
Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
New
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...
New
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible.
total = 10
while total != 0
...
New
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
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
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
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








