A Request is a client-side representation of a request, that can be manipulated client-side before actually serialising into a JSON message and sending to the server. For example, this:
import EnTrance.Request as Request
Request.new "order_ice_cream"
|> Request.addString "flavour" "chocolate"
|> Request.addBool "with_flake" Truewould end up as a JSON request to the server containing
{
"msg_type": "order_ice_cream",
"flavour": "chocolate",
"with_flake": true
}(Actually, it also adds a "target": "defaultTarget", but you don't have to
care about this unless you're writing a particular type of complex app, in
which case you want to use Target.set on most
requests yourself.)
In the typical case, you would finish with Channel.sendSimpleRpc or Channel.sendRpc, eg:
Request.new "order_ice_cream"
|> Request.addString "flavour" "chocolate"
|> Request.addBool "with_flake" True
|> Channel.sendSimpleRpc modelSending invokes some extra magic, whereby the actual JSON going to the server would be something like:
{
"msg_type": "order_ice_cream",
"flavour": "chocolate",
"with_flake": true,
"channel": "my_app",
"id": <some auto-generated unique identifier>
}so that the reply gets routed back to the sending channel, and any out-of-order or outdated replies get automatically dropped.
If you add multiple values for the same key, then the most recent value wins. For example:
Request.new "order_ice_cream"
|> Request.addString "flavour" "chocolate"
|> Request.addString "flavour" "strawberry"
|> Request.encodeyields:
{
"msg_type": "order_ice_cream",
"flavour": "strawberry"
}Create a request Param value containing just a req_type parameter.
(Actually it also creates a default target value, but you don't have to care.
See Target if interested.)
Add a 'List String'-valued parameter to a request.
Add an arbitrary 'Encode.Value' parameter to a request
The most common use of a Request is calling something like Channel.sendRpc with it. But you can also just encode it as JSON if you like.
A request value, that can be built up client-side, before eventually being sent over a channel to the server (typically using Channel.sendSimpleRpc or Channel.sendRpc).