Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to combine method & route ? #142

Open
whatsthecraic opened this issue Nov 18, 2021 · 1 comment
Open

How to combine method & route ? #142

whatsthecraic opened this issue Nov 18, 2021 · 1 comment

Comments

@whatsthecraic
Copy link

e.g.

mux(
method("GET", route("path/to/this", handle_1)),
method("POST", route("path/to/that", handle_2)),
notfound(),
)
@cmcaine
Copy link
Collaborator

cmcaine commented Nov 26, 2021

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants