Skip to content

Documentation on how routes are prioritized #45

@hcarty

Description

@hcarty

Given a modified version of the README example:

open Opium.Std

let print_param = get "/hello/:name" begin fun req ->
    `String ("Hello " ^ param req "name") |> respond'
  end

let print_other = get "**" begin fun req ->
    `String "Hello everyone else" |> respond'
  end

let () =
  App.empty
  (* Order matters! *)
  |> print_other
  |> print_param
  (* Order matters! *)
  |> App.run_command

With this code I see "Hello test" if I GET /hello/test and "Hello everyone else" if I use other paths. However, if I swap the lines between the comments above then the only response "Hello everyone else". OCaml 4.02.3 + opium 0.13.3 + cohttp 0.19.3 from opam.

I'm not sure what the right approach is here. It's useful to be able to have specific routes with an catch-all to handle all other requests. It would be useful if the right way to do this were shown in the README or somewhere similarly visible.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions