dream icon indicating copy to clipboard operation
dream copied to clipboard

More elaborate routing (e.g. match only ints, etc.)

Open aantron opened this issue 4 years ago • 6 comments

For example, allow a way to check that :id in /blah/:id is an integer before matching the route.

cc @jsthomas @c-cube for interest.

aantron avatar Jul 09 '21 03:07 aantron

dream-routes from @ulrikstrid adapts @anuragsoni's Routes to Dream:

let () =
  Dream.run
  @@ Dream.logger
  @@ Dream_routes.routes Routes.[
    empty @--> (fun _request ->
      Dream.html "Good morning, world!");

    s "echo" / int /? nil @--> (fun integer _request ->
        Dream.html @@ Printf.sprintf "integer: %i" integer);

    s "echo" / str /? nil @--> (fun word _request ->
      Dream.html word);
  ]
  @@ Dream.not_found

aantron avatar Jul 10 '21 06:07 aantron

Would you like a PR to Community Projects section in README?

thangngoc89 avatar Jul 10 '21 08:07 thangngoc89

Note that dream-routes does not yet handle different methods and we might need to discuss a nice API for that.

@thangngoc89 I think the community projects is a list of vetted projects that are actually recommended. So I guess a issue to ask for inclusion is what should happen 🙂

ulrikstrid avatar Jul 10 '21 10:07 ulrikstrid

I think after dream-routes supports methods, and after a bit of review, we can add it to the list.

aantron avatar Jul 10 '21 10:07 aantron

See ulrikstrid/dream-routes#1

ulrikstrid avatar Jul 11 '21 07:07 ulrikstrid