Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DSL Discuss #105

Open
falood opened this issue Jul 17, 2018 · 2 comments
Open

DSL Discuss #105

falood opened this issue Jul 17, 2018 · 2 comments

Comments

@falood
Copy link
Member

falood commented Jul 17, 2018

Hidden variables or definite ones? Or better ideas?

  # Option 1
  get "path", fn conn, _params ->
    json(conn, %{hello: :hehe})
  end

  # Option 2
  get "path" do
    json(conn, %{hello: :hehe})
  end


  # Option 1
  rescue_from Unauthorized, fn conn, _params, error ->
    conn
    |> put_status(400)
    |> json(%{error: :unauthorized, error})
  end

  rescue_from :all, &rescue_all_errors/3


  # Option 2
  rescue_from Unauthorized, as: error do
    conn
    |> put_status(400)
    |> json(%{error: :unauthorized, error})
  end

  rescue_from :all, with: :rescue_all_errors
@jalcine
Copy link
Contributor

jalcine commented Jul 18, 2018

Taking some time to look at this, I'm opting towards option 1.

I'm leaning towards it because it's a bit self-documenting and reads a bit more idiomatically for Elixir. In order to GET the route named "path", invoke this function.

The second one seems a bit more magical and doesn't give an explicit contract for the route handler.

@falood
Copy link
Member Author

falood commented Jul 18, 2018

I also like option 1 better.
but it will be quite different with plug router.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants