rockydgeekgod rockydgeekgod - 11 months ago 55
reST (reStructuredText) Question

Does Maru support only path params and not query params?

I was getting me feet wet with

and decided to use Maru as the RESTful framework. I went through the docs and googled for a day but could not find any documentation or examples on how to parse query params.

I want something like this


I want to parse the above url and populate a map with the query params
. Does Maru support this kind of operation?

Answer Source

I couldn't find any functionality to do this in Maru's source code, but since Maru uses the plug package internally and allows full access to customizing the plug pipeline, you can plug in Plug.Conn.fetch_query_params and then access the params using conn.params:

defmodule MyApp do
  use Maru.Router
  plug :fetch_query_params

  get do
    json(conn, conn.params)
$ curl '\[\]=quux'