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

Add ability to pass params through to action even if proto is defined #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

hayesgm
Copy link
Owner

@hayesgm hayesgm commented Jan 23, 2017

This patch adds the ability to pass params to action calls even when we've defined a proto. This is to simply the case when working with legacy code where data is included in parameters that are outside the scope of the defined protobufs. E.g. imagine this case:

curl http://example.com/ping?timeout=500

In this simple case, we would likely define the following route in HyperBuffs,

defmodule MyRouter do
  # ...

  get "/ping", HomeController, :ping, private: %{req: :none, resp: Defs.Pong}
end
defmodule HomeController do
  # ...
  def ping(conn, params) do
    Defs.Pong.new()
  end

That is, since there's no real body to parse, we accept nothing for the request protobuf. To accept the timeout field, we could either define a body:

message Ping {
  int32 timeout = 1;
}
defmodule HomeController do
  # ...
  def ping(conn, ping=%Defs.Ping{}) do
    :timer.kill_after(:timer.seconds(Ping.timeout))
    Defs.Pong.new()
  end

or, in this case, we could simply now call passthrough:

defmodule MyRouter do
  # ...

  get "/ping", HomeController, :ping, private: %{req: :none, resp: Defs.Pong, passthrough: true}
end
defmodule HomeController do
  # ...
  def ping(conn, params) do
    :timer.kill_after(:timer.seconds(params["timeout"]))
    Defs.Pong.new()
  end

The choice is whether or not the Ping message is truly a defined input schema. The thought is that legacy projects adopting HyperBuffs may allow some param input as they shift purely onto protobuf definitions.

Note: this can also be accomplished by calling conn.params["timeout"], but it does not seem it's the intention of Phoenix actions to dig into the conn object for parameters.

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

Successfully merging this pull request may close these issues.

1 participant