Mux.jl
Mux.jl copied to clipboard
How to combine method & route ?
e.g.
mux(
method("GET", route("path/to/this", handle_1)),
method("POST", route("path/to/that", handle_2)),
notfound(),
)
Each branch needs to terminate somewhere with a middleware that expects a single argument (like notfound()
or respond("something")
). route
and method
are both branching middlewares: they expect not to be last in the tree of functions to call.
Try:
julia> using Mux
julia> using Mux: notfound
julia> @app app = (
Mux.defaults,
method("GET",
route("path/to/this", respond("hi")),
notfound()
),
method("POST",
route("path/to/that", respond("bye!")),
notfound()
),
notfound(),
)
julia> serve(app)
Task (runnable) @0x00007fbbcbe931f0
shell> curl http://localhost:8000/path/to/this
hi
shell> curl -X POST http://localhost:8000/path/to/this
Not found
shell> curl -X POST http://localhost:8000/path/to/that
bye!