Timestamp microservices doubts

Hi, this is my current status of the project…

and the code https://glitch.com/edit/#!/timestmp-microsrvice

one thing i didnt understand is the importance of the “?” after the “date_string”
in the path of the api.get
specfically here app.get("/api/timestamp/:date_string?" …

if i dont use the ? the projects never works for when date_string is empty. its not able to perform get request in that case. i was hoping to get some clarity regarding the importance of using the question mark… and read up a bit more about it.

Hi @p.raksahb

The ? in a URL denotes the start of a query string, where you can pass key-value pairs as extra parameters to the resource, separated by &.

They look something like: ?key1=value1&key2=value2

Here’s the wiki on them: https://en.wikipedia.org/wiki/Query_string

ok but im still a bit confused on why the link doesnt work without it.
in case of me putting like myproject/api/timestamp only… it doesnt perform the get request

Oh sorry, I misread your question.

I believe the question mark here: app.get("/api/timestamp/:date_string?" actually means that the param (:date_string) is optional in express, kinda of like a regex pattern.

So basically, if you were to navigate to “<host>/api/timestamp/” it won’t match against that URL pattern because without a question mark, it expects at least something to be there, with the question mark it doesn’t matter and so will match and work.

1 Like