Comments (7)
Here's how I do a post request:
13 body = "code=#{code}&grant_type=authorization_code&client_secret=CDRPVW63YBXLHSPGL4Q25AFJKTXC7EYWOJ6LOQEE3UDIOABT6N&client_id=7EBFEB24BRVOV6J5KG"
14 case HTTPoison.post("https://www.eventbrite.com/oauth/token", body, [{<<"Content-Type">>, <<"application/x-www-form-urlencoded">>}]) do
15 {:ok, %HTTPoison.Response{status_code: 200, body: body}} ->
16 IO.puts "BODY :: [[#{body}]]"
17 {:ok, %HTTPoison.Response{status_code: 404, body: body}} ->
18 IO.puts "Not found :-( #{body}"
19 {:ok, %HTTPoison.Response{status_code: status_code, body: body}} ->
20 IO.puts "I got a different code #{status_code} -- what the hell? #{body}"
21 {:error, %HTTPoison.Error{reason: reason}} ->
22 IO.inspect reason
23 end
from code-for-conduct.
Added a new route like this:
9 get "/auth", CodeForConduct.PageController, :auth, as: :pages
from code-for-conduct.
When I want different handling based on query params, I can do it like this:
# when there is a "code" query param
def auth(conn, %{"code" => code}) do
...
end
# otherwise
def auth(conn, _params) do
...
end
Both of these are the same method, and they pattern match on the incoming parameters to select which body to execute.
from code-for-conduct.
How to do a redirect from a controller function:
29 redirect conn, "https://www.eventbrite.com/oauth/authorize?response_type=code&client_id=7EBFEB24BRVOV6J5KG"
from code-for-conduct.
# Where body is a map
case Poison.encode body do
{:ok, json} -> HTTPoison.post('http://localhost:3300', json)
{:error, r} -> IO.puts r
end
from code-for-conduct.
# How to get environment variable, and default if not found
[port: System.get_env("PORT") || 4000]
from code-for-conduct.
ERLANG NOT HAVE MUTABLE STATE.
To be more specific:
put_session(conn, "key", "value")
is NOT the same as:
conn = put_session(conn, "key", "value")
Use the second one, otherwise you just threw away your session value.
from code-for-conduct.
Related Issues (1)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from code-for-conduct.