params does not contain POST Body in Elixir / Phoenix -
i try build simple rest api. not include database or models.
here's router:
defmodule zentonies.router use zentonies.web, :router pipeline :browser plug :accepts, ["html"] plug :fetch_session plug :fetch_flash plug :protect_from_forgery plug :put_secure_browser_headers end pipeline :api plug :accepts, ["json"] end scope "/v1/events/", zentonies pipe_through :api post "/call", pagecontroller, :call end end
here controller:
defmodule zentonies.pagecontroller require logger import joken use zentonies.web, :controller def index(conn, _params) render conn, "index.html" end def call(conn, params) logger.debug inspect(params) conn |> put_status(200) |> text("response.") end end
now, if http post endpoint, inspect(params)
not return json body of post request. instead returns :call
.
any appreciated!
a call/2
function defined phoenix own use dispatch correct action in every phoenix controller. creating function name you're overriding builtin functionality. you'll have use different name action. check out section "controllers plugs" in documentation of phoenix.controller.pipeline
:
controllers plugs
like routers, controllers plugs, wired dispatch particular function called action.
for example, route:
get "/users/:id", usercontroller, :show
will invoke
usercontroller
plug:usercontroller.call(conn, :show)
which trigger plug pipeline , invoke inner action plug dispatches
show/2
function inusercontroller
.
Comments
Post a Comment