title: How To Pass Multiple Parameters In A URL To Plug
body: <p>So I'm trying to pass multiple parameters in a URL to plug.  This is the URL I'm using for testing:</p>
  
  <pre><code>http://localhost:4000/uid=ToddFlanders&amp;pwd=MyTestPword
  </code></pre>
  
  <p>And this is the code:</p>
  
  <pre><code>defmodule Sci do
      @userid "uid"
      @password "pwd"
      import Plug.Conn
      import Plug.Conn.Utils
      use Plug.Router
  
  
      plug :match
      plug :dispatch
  
      get "/:args" do
          %{@userid =&gt; usr} = params(args)
          %{@password =&gt; pass} = params(args)
  
          send_resp(conn, 200, "Hello #{usr}. Your password is #{pass}")
      end
  
      match _ do
          send_resp(conn, 404, "oops")
    end
  
    def start do
      Plug.Adapters.Cowboy.http Sci, [], port: 4000
    end
  
    def stop do
      Plug.Adapters.Cowboy.shutdown Sci.HTTP
    end
  end
  </code></pre>
  
  <p>If I pass just one argument (either uid or pwd) it matches fine.  If I remove the <code>?</code> at the front of the query string it fails--throws an exception. </p>
  
  <p>I also tried this:</p>
  
  <pre><code>get "/:args" do
    %{@userid =&gt; usr, @password =&gt; pass} = params(args)
  </code></pre>
  
  <p>Also didn't work.  So two questions:</p>
  
  <p>1.) Is that the right way to pass multiple parameters in a URL?</p>
  
  <p>2.) Is there some trick to get plug to see both parameters?</p>
  
  <p>Any thoughts or insights would be welcome--even a suggestion of a better way to do this.</p>
  
  <p>Elixir v0.15.1 and Plug v0.5.1 </p>
  
  <p>EDIT:  </p>
  
  <p>Adding a stacktrace per Jose's comment:</p>
  
  <pre><code>iex(2)&gt; 07:46:56.499 [error] Error in process &lt;0.232.0&gt; with exit value: {[{reason,{badmatch,#{}}},{mfa,{'Elixir.Plug.Adapters.Cowboy.Handler',init,3}},{stacktrace,[{'Elixir.Sci','-do_match/2-fun-0-',2,[{file,"lib/sci.ex"},{line,18}]},{'Eli
  xir.Sci',call,2,[{file,"lib/sci.ex"},{line,1}]},{'Elixir.Plug.Adapters.Cowboy.Handler'...                                                                                                                                                       
  
  
  iex(2)&gt; 07:46:56.510 [error] Ranch listener Sci.HTTP had connection process started with :cowboy_protocol:start_link/4 at #PID&lt;0.232.0&gt; exit with reason: {[reason: {:badmatch, %{}}, mfa: {Plug.Adapters.Cowboy.Handler, :init, 3}, stacktrace:
   [{Sci, :"-do_match/2-fun-0-", 2, [file: 'lib/sci.ex', line: 18]}, {Sci, :call, 2, [file: 'lib/sci.ex', line: 1]}, {Plug.Adapters.Cowboy.Handler, :init, 3, [file: 'lib/plug/adapters/cowboy/handler.ex', line: 7]}, {:cowboy_handler, :handler_
  init, 4, [file: 'src/cowboy_handler.erl', line: 64]}, {:cowboy_protocol, :execute, 4, [file: 'src/cowboy_protocol.erl', line: 435]}], req: [socket: #Port&lt;0.5168&gt;, transport: :ranch_tcp, connection: :keepalive, pid: #PID&lt;0.232.0&gt;, method: "G
  ET", version: :"HTTP/1.1", peer: {{127, 0, 0, 1}, 63880}, host: "localhost", host_info: :undefined, port: 4000, path: "/uid=ToddFlanders&amp;pwd=MyTestPassword", path_info: :undefined, qs: "", qs_vals: :undefined, bindings: [], headers: [{"host
  ", "localhost:4000"}, {"connection", "keep-alive"}, {"cache-control", "max-age=0"}, {"accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"}, {"user-agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/53
  7.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36"}, {"accept-encoding", "gzip,deflate,sdch"}, {"accept-language", "en-US,en;q=0.8"}], p_headers: [{"connection", ["keep-alive"]}], cookies: :undefined, meta: [], body_state: :waitin
  g, buffer: "", multipart: :undefined, resp_compress: false, resp_state: :waiting, resp_headers: [], resp_body: "", onresponse: :undefined], opts: {Sci, []}], [{:cowboy_protocol, :execute, 4, [file: 'src/cowboy_protocol.erl', line: 435]}]}  
  
  iex(2)&gt; 07:46:56.969 [error] Error in process &lt;0.233.0&gt; with exit value: {[{reason,{badmatch,#{}}},{mfa,{'Elixir.Plug.Adapters.Cowboy.Handler',init,3}},{stacktrace,[{'Elixir.Sci','-do_match/2-fun-0-',2,[{file,"lib/sci.ex"},{line,18}]},{'Eli
  xir.Sci',call,2,[{file,"lib/sci.ex"},{line,1}]},{'Elixir.Plug.Adapters.Cowboy.Handler'...                                                                                                                                                       
  
  
  iex(2)&gt; 07:46:56.971 [error] Ranch listener Sci.HTTP had connection process started with :cowboy_protocol:start_link/4 at #PID&lt;0.233.0&gt; exit with reason: {[reason: {:badmatch, %{}}, mfa: {Plug.Adapters.Cowboy.Handler, :init, 3}, stacktrace:
   [{Sci, :"-do_match/2-fun-0-", 2, [file: 'lib/sci.ex', line: 18]}, {Sci, :call, 2, [file: 'lib/sci.ex', line: 1]}, {Plug.Adapters.Cowboy.Handler, :init, 3, [file: 'lib/plug/adapters/cowboy/handler.ex', line: 7]}, {:cowboy_handler, :handler_
  init, 4, [file: 'src/cowboy_handler.erl', line: 64]}, {:cowboy_protocol, :execute, 4, [file: 'src/cowboy_protocol.erl', line: 435]}], req: [socket: #Port&lt;0.5174&gt;, transport: :ranch_tcp, connection: :keepalive, pid: #PID&lt;0.233.0&gt;, method: "G
  ET", version: :"HTTP/1.1", peer: {{127, 0, 0, 1}, 63881}, host: "localhost", host_info: :undefined, port: 4000, path: "/favicon.ico", path_info: :undefined, qs: "", qs_vals: :undefined, bindings: [], headers: [{"host", "localhost:4000"}, {"
  connection", "keep-alive"}, {"accept", "*/*"}, {"user-agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36"}, {"accept-encoding", "gzip,deflate,sdch"}, {"accept-language", "e
  n-US,en;q=0.8"}], p_headers: [{"connection", ["keep-alive"]}], cookies: :undefined, meta: [], body_state: :waiting, buffer: "", multipart: :undefined, resp_compress: false, resp_state: :waiting, resp_headers: [], resp_body: "", onresponse: 
  :undefined], opts: {Sci, []}], [{:cowboy_protocol, :execute, 4, [file: 'src/cowboy_protocol.erl', line: 435]}]}                                                                                                                                 
  </code></pre>
  
  <p>EDIT 2: 
  I had jotted down the wrong URL above; that's now corrected.  Also to add to the question, if I make the URL this: <code>http://localhost:4000/?uid=ToddFlanders&amp;pwd=MyTestPword</code>, the code jumps down to the <code>match _ do</code> clause</p>