From 7ed80ce21a946856fa227cc03e64781fa9176fc5 Mon Sep 17 00:00:00 2001 From: Liumingxun Date: Tue, 27 May 2025 00:04:06 +0800 Subject: [PATCH 1/2] chore(docs): fix example path parameter --- topics/server-requests-and-responses.topic | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/topics/server-requests-and-responses.topic b/topics/server-requests-and-responses.topic index 6e92c9e23..43936abd8 100644 --- a/topics/server-requests-and-responses.topic +++ b/topics/server-requests-and-responses.topic @@ -371,9 +371,10 @@

The route you would add is - /tasks/byPriority/{priority} - where {priority} represents a query parameter that you will need to extract at runtime. The - query parameter can have any name you like, but priority seems the obvious choice. + /tasks/byPriority/{priority?} + where {priority?} represents a query parameter that you will need to extract at runtime, + and the question mark is used to indicate that a parameter is optional. The query parameter can have + any name you like, but priority seems the obvious choice.

The process to handle the request can be summarized as follows: @@ -965,4 +966,4 @@ RESTful API for your task manager that generates JSON files.

- \ No newline at end of file + From 53cca69d746854ab3097762ebf5240344850dc91 Mon Sep 17 00:00:00 2001 From: Liumingxun Date: Tue, 27 May 2025 00:12:45 +0800 Subject: [PATCH 2/2] Update server-requests-and-responses.topic --- topics/server-requests-and-responses.topic | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/topics/server-requests-and-responses.topic b/topics/server-requests-and-responses.topic index 43936abd8..018d86f09 100644 --- a/topics/server-requests-and-responses.topic +++ b/topics/server-requests-and-responses.topic @@ -401,7 +401,7 @@ get("/tasks") { ... } //add the following route - get("/tasks/byPriority/{priority}") { + get("/tasks/byPriority/{priority?}") { val priorityAsText = call.parameters["priority"] if (priorityAsText == null) { call.respond(HttpStatusCode.BadRequest) @@ -429,7 +429,7 @@

As summarized above, you have written a handler for the URL - /tasks/byPriority/{priority} + /tasks/byPriority/{priority?} . The symbol priority represents the query parameter that the user has added. Unfortunately, on the server there's @@ -710,7 +710,7 @@ get("/tasks") { ... } - get("/tasks/byPriority/{priority}") { … } + get("/tasks/byPriority/{priority?}") { … } } } @@ -898,7 +898,7 @@ //Code remains the same } - get("/byPriority/{priority}") { + get("/byPriority/{priority?}") { //Code remains the same } @@ -944,7 +944,7 @@ ) } - get("/byPriority/{priority}") { + get("/byPriority/{priority?}") { //Code remains the same }