Clova v0.2.0 Clova.Dispatcher View Source
A plug for dispatching CEK request to your Clova
implementation.
Pass your callback module as the dispatch_to
argument to the plug.
This plug expects the Plug.Conn
struct to have been parsed by Clova.Parser
and validated by
Clova.Validator
.
This plug encodes the callback response into JSON and places it into the connection’s response body.
This plug also sets the connection status, meaning your endpoint can simply call Plug.Conn.send_resp/1
with the conn
argument.
plug Plug.Parsers, parsers: [Clova.Parser]
plug Clova.Validator, app_id: "com.example.my_extension"
plug Clova.Dispatcher, dispatch_to: MyExtension
plug :match
plug :dispatch
post "/endpoint" do
send_resp(conn)
end
If you wish to disable the JSON encoding, the skip_json_encoding
option is available.
When skipping JSON encoding, the Clova.Response
struct returned from your Clova
implementation is placed into the :clova_response
assign. In this case you need to set the
Plug.Conn
’s response body yourself.
plug Plug.Parsers, parsers: [Clova.Parser]
plug Clova.Validator, app_id: "com.example.my_extension"
plug Clova.Dispatcher, dispatch_to: MyExtension, skip_json_encoding: true
plug :match
plug :dispatch
post "/endpoint" do
conn
|> put_resp_content_type("application/json")
|> send_resp(conn.status, Poison.encode!(conn.assigns.clova_response))
end
Link to this section Summary
Link to this section Functions
Callback implementation for Plug.call/2
.
Callback implementation for Plug.init/1
.