2021-03-30 19:50:14 +03:00
..
2021-03-30 19:50:14 +03:00
2021-03-30 19:50:14 +03:00
2021-03-30 19:50:14 +03:00
2021-03-30 19:50:14 +03:00

e-json


TODO

let show_form ?message request =
  <html>
    <body>
%     begin match message with
%     | None -> ()
%     | Some message ->
        <p>You entered: <b><%s message %>!</b></p>
%     end;
      <%s! Dream.Tag.form ~action:"/" request %>
        <input name="message" autofocus>
      </form>
    </body>
  </html>

let () =
  Dream.run
  @@ Dream.logger
  @@ Dream.sessions_in_memory
  @@ Dream.router [

    Dream.get  "/"
      (fun request ->
        Dream.respond (show_form request));

    Dream.post "/"
      (fun request ->
        match%lwt Dream.form request with
        | `Ok ["message", message] ->
          Dream.respond (show_form ~message request)
        | _ ->
          Dream.empty `Bad_Request);

  ]
  @@ Dream.not_found
$ dune exec --root . ./promise.exe

TODO


Next steps:

  • b-session introduces session management for associating state with clients.
  • c-cookie shows cookie handling in Dream.

Up to the tutorial index