Reorder some examples

This commit is contained in:
Anton Bachin 2021-04-05 00:08:28 +03:00
parent 65fe6bd258
commit 29358cf376
29 changed files with 37 additions and 39 deletions

View File

@ -40,9 +40,9 @@ When you run this server and visit
You can write your own messages to the log using
[`Dream.log`](https://aantron.github.io/dream/#val-log). See example
[**`9-logging`**](../9-logging/#files) for more logging options. Now that we
have the logger, we will use it in all other examples, even though it's not
really necessary — it just makes it much easier to see what is going on.
[**`a-log`**](../a-log/#files) for more logging options. Now that we have the
logger, we will use it in all other examples, even though it's not really
necessary — it just makes it much easier to see what is going on.
<br>

View File

@ -45,7 +45,7 @@ Found` when that happens.
Except for the status code, the `404 Not Found` response is *completely* empty,
so it might not display well in your browser. In example
[**`8-error`**](../8-error/#files), we will decorate all error responses with
[**`9-error`**](../9-error/#files), we will decorate all error responses with
an error template in one central location.
<br>
@ -68,8 +68,8 @@ The router can do more than match simple routes:
- [**`4-counter`**](../4-counter/#files) counts requests, and exposes a special
route for getting the count.
- [**`5-echo`**](../5-echo/#files) is dynamic in another way: by reading the
request body.
- [**`5-promise`**](../5-promise/#files) introduces Lwt, the promise library
used by Dream.
<br>

View File

@ -36,9 +36,8 @@ which means they usually also
This example's middleware only does something *before* calling the
`inner_handler`. To do something *after*, we will need to await the response
promise with [Lwt](https://github.com/ocsigen/lwt#readme), the promise library
used by Dream. The next example, [**`5-echo`**](../5-echo/#files), already shows
a bit of it, but example [**`a-promise`**](../a-promise/#files) introduces Lwt
more fully.
used by Dream. The next example, [**`5-promise`**](../5-promise/#files), does
exactly that!
<!-- TODO
<br>
@ -52,10 +51,10 @@ you are writing middleware to publish in a library. It's fine to use a global
**Next steps:**
- [**`5-echo`**](../5-echo/#files) responds to `POST` requests and reads their
- [**`5-promise`**](../5-promise/#files) shows a middleware that awaits
responses using Lwt.
- [**`6-echo`**](../6-echo/#files) responds to `POST` requests and reads their
bodies.
- [**`6-template`**](../6-template/#files) embeds HTML in OCaml... or... OCaml
in HTML?
<br>

View File

@ -15,18 +15,17 @@ list below and jump to whatever interests you!
different paths.
- [**`4-counter`**](4-counter/#files) &nbsp;&mdash;&nbsp; the first *custom*
middleware!
- [**`5-echo`**](5-echo/#files) &nbsp;&mdash;&nbsp; reads request bodies.
- [**`6-template`**](6-template/#files) &nbsp;&mdash;&nbsp; renders responses
from inline HTML templates and guards against XSS.
- [**`7-debug`**](7-debug/#files) &nbsp;&mdash;&nbsp; includes detailed
information
about errors in responses.
- [**`8-error`**](8-error/#files) &nbsp;&mdash;&nbsp; customize all error
responses in one place.
- [**`9-log`**](9-log/#files) &nbsp;&mdash;&nbsp; writing messages to Dream's
log.
- [**`a-promise`**](a-promise/#files) &nbsp;&mdash;&nbsp; introduces Lwt, the
- [**`5-promise`**](5-promise/#files) &nbsp;&mdash;&nbsp; introduces Lwt, the
promise library used by Dream.
- [**`6-echo`**](6-echo/#files) &nbsp;&mdash;&nbsp; reads request bodies.
- [**`7-template`**](7-template/#files) &nbsp;&mdash;&nbsp; renders responses
from inline HTML templates and guards against XSS.
- [**`8-debug`**](8-debug/#files) &nbsp;&mdash;&nbsp; includes detailed
information about errors in responses.
- [**`9-error`**](9-error/#files) &nbsp;&mdash;&nbsp; customize all error
responses in one place.
- [**`a-log`**](a-log/#files) &nbsp;&mdash;&nbsp; writing messages to Dream's
log.
- [**`b-session`**](b-session/#files) &nbsp;&mdash;&nbsp; associates state with
client sessions.
- [**`c-cookie`**](c-cookie/#files) &nbsp;&mdash;&nbsp; sets custom cookies.

View File

@ -48,8 +48,8 @@ and middleware = handler -> handler
Examples
{{:https://github.com/aantron/dream/tree/master/example/4-counter#files}
[4-counter]} and
{{:https://github.com/aantron/dream/tree/master/example/a-promise#files}
[a-promise]} show user-defined middlewares:
{{:https://github.com/aantron/dream/tree/master/example/5-promise#files}
[5-promise]} show user-defined middlewares:
{[
let count_requests inner_handler request =
@ -102,8 +102,8 @@ and outgoing
and 'a promise = 'a Lwt.t
(** Dream uses {{:https://github.com/ocsigen/lwt} Lwt} for promises and
asynchronous I/O. See example
{{:https://github.com/aantron/dream/tree/master/example/a-promise#files}
[a-promise]}. *)
{{:https://github.com/aantron/dream/tree/master/example/5-promise#files}
[5-promise]}. *)
@ -590,8 +590,8 @@ val all_cookies : request -> (string * string) list
val body : 'a message -> string promise
(** Retrieves the entire body. Stores a reference, so {!Dream.body} can be used
many times. See example
{{:https://github.com/aantron/dream/tree/master/example/5-echo#files}
[5-echo]}. *)
{{:https://github.com/aantron/dream/tree/master/example/6-echo#files}
[6-echo]}. *)
val with_body : string -> response -> response
(** Replaces the body. *)
@ -929,8 +929,8 @@ let render message =
v}
See example
{{:https://github.com/aantron/dream/tree/master/example/6-template#files}
[6-template]}.
{{:https://github.com/aantron/dream/tree/master/example/7-template#files}
[7-template]}.
To build the template, add this to [dune]:
@ -1413,8 +1413,8 @@ val log : ('a, Format.formatter, unit, unit) format4 -> 'a
{{:http://caml.inria.fr/pub/docs/manual-ocaml/libref/Format.html#VALfprintf}
[Format]}. The rest of the arguments are determined by the format string.
See example
{{:https://github.com/aantron/dream/tree/master/example/9-log#files}
[9-log]}.
{{:https://github.com/aantron/dream/tree/master/example/a-log#files}
[a-log]}.
{[
Dream.log "Counter is now: %i" counter;
@ -1442,8 +1442,8 @@ val error : ('a, unit) conditional_log
level} is [`Error] or higher. This scheme is based on the
{{:https://erratique.ch/software/logs/doc/Logs/index.html} Logs} library.
See example
{{:https://github.com/aantron/dream/tree/master/example/9-log#files}
[9-log]}.
{{:https://github.com/aantron/dream/tree/master/example/a-log#files}
[a-log]}.
{[
Dream.error (fun log ->
@ -1486,8 +1486,8 @@ val sub_log : string -> sub_log
]}
See [README] of example
{{:https://github.com/aantron/dream/tree/master/example/9-log#files}
[9-log]}. *)
{{:https://github.com/aantron/dream/tree/master/example/a-log#files}
[a-log]}. *)
val initialize_log :
?backtraces:bool ->
@ -1671,8 +1671,8 @@ type error_handler = error -> response option promise
val error_template :
(string option -> response -> response promise) -> error_handler
(** Builds an {!error_handler} from a template. See example
{{:https://github.com/aantron/dream/tree/master/example/8-error#files}
[8-error]}.
{{:https://github.com/aantron/dream/tree/master/example/9-error#files}
[9-error]}.
{[
let my_error_handler =