Srene

Srene

HTTPosion request format

Hi…
I have the following in python:

response = requests.post(url,data=parameters, auth=(api_key, ‘’))

What is the HTTPoison ot HTTPotion equivalent for this.
Thanks.

Most Liked

NobbZ

NobbZ

Please do not assume that anyone does know what a certain snippet in a foreign language does. Please try to explain how the request should look like.

collegeimprovements

collegeimprovements

HTTPoison is cool but take a look at Tesla also.

Link: https://github.com/teamon/tesla
Documentation: https://hexdocs.pm/tesla/api-reference.html

markkauffman2000

markkauffman2000

HTTPoison POST Example. Auth goes into the trailing options.
post!(url, body, headers \\ [], options \\ [])

iex(7)> {code, response} = HTTPoison.post "https://bd-partner-a-system.blackboard.com/learn/api/public/v1/oauth2/token", "grant_type=client_credentials", [{"Content-Type",  "application/x-www-form-urlencoded"}], [hackney: [basic_auth: {"user", "password"}] ]

The code is :ok, or not. The response will be an %HTTPoison.Response

HTTPotion POST Example. Most everything, including auth, goes into options.
response = HTTPotion.post(url, options \\ [])

iex(2)> options =  [body: "grant_type=client_credentials",
     headers: ["Content-Type": "application/x-www-form-urlencoded"],
     basic_auth: {"user","password"}]
iex(3)>response = HTTPotion.post("https://bd-partner-a-system.blackboard.com", options)

The response will be an %HTTPotion.Response.

Docs are easily found with a search. Between the docs you find and the above examples, you should be set!

Linuus

Linuus

Have you looked at the documentation?

Here’s the post function: https://hexdocs.pm/httpoison/HTTPoison.html#post/4

Something along these lines is what you want to do:

case HTTPoison.post(url, body, headers) do
  {:ok, response} -> IO.inspect(response) # Request went through, do something :)
  {:error, reason} -> IO.inspect(reason) # Request failed...
end

Also: https://github.com/edgurgel/httpoison#usage

Where Next?

Popular in Questions Top

vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
pgiesin
This should be a simple problem but I just can’t seem to figure it out. I have a standalone Elixir app that won’t find the database. Dep...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lis...
New
Phillipp
Hey, I have a NanoPi-M3 and try to install Elixir on their Ubuntu image. I followed the Raspberry Pi installation instructions from the ...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
Exadra37
Sometimes I want to check if the input into a function is not a blank string. My first approach: defmodule Example do def do_stuff(s...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New

Other popular topics Top

peerreynders
Manning 2016 Halloween weekend sale via Deal of the Day Friday, October 28 - Half off all MEAPs - code WM102816LT Saturday, October 29 ...
326 29600 154
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
sergio
I couldn’t find any guides that worked well with Phoenix 1.6.0 and esbuild. I hope this helps people test the waters and eases you into t...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
vac
Hi, I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
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
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New

We're in Beta

About us Mission Statement