From 388a91ee79333fc30b2e3d2fb8d97899c8ad59f0 Mon Sep 17 00:00:00 2001 From: r3mu$ n0x Date: Wed, 7 Nov 2018 20:26:50 +0200 Subject: [PATCH] Fix route registration order in rest_resource example --- src/examples/rest_resource/main.cpp | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/examples/rest_resource/main.cpp b/src/examples/rest_resource/main.cpp index 02b011a..da43f83 100644 --- a/src/examples/rest_resource/main.cpp +++ b/src/examples/rest_resource/main.cpp @@ -34,18 +34,8 @@ int main(int, char const**) { served::multiplexer mux; - mux.handle("/customers") - .get([](served::response & res, const served::request & req) { - (void) res; - (void) req; - // list customers - }) - .post([](served::response & res, const served::request & req) { - (void) res; - (void) req; - // create customer - }); - + // register a more specialized route first, otherwise all requests with + // "/customers" prefix will be routed to "/customers" handlers mux.handle("/customers/{id}") .get([](served::response & res, const served::request & req) { (void) res; @@ -63,6 +53,18 @@ int main(int, char const**) // delete customer req.params["id"] }); + mux.handle("/customers") + .get([](served::response & res, const served::request & req) { + (void) res; + (void) req; + // list customers + }) + .post([](served::response & res, const served::request & req) { + (void) res; + (void) req; + // create customer + }); + served::net::server server("127.0.0.1", "8123", mux); server.run(10);