Every morning, each courier opens the app, which greets them by their first name. Margot wants the API to do it.
Your mission
- In
routes/web.go, add aGET /couriers/{prenom}route (prenomis French for “first name”). - It reads the
prenomparameter from the URL. - It responds with the JSON
{"coursier": "Margot", "message": "Have a good round, Margot!"}, with the first name from the URL in both keys.
Reminder
As in Laravel, a route parameter is declared between curly braces. Goravel doesn't pass it as an argument to the function: you ask the request for it, ctx.Request().Route("prenom"), which returns a string.
In Go, := declares a variable and gives it its value in one go; its type is inferred from the value. prenom := ctx.Request().Route("prenom") makes prenom a string. Once it's declared, you change it with = alone. And the Go compiler refuses a declared variable that is never used (the browser's interpreter is more forgiving, a real project is not).