The couriers' API

Exercise 1 of 2 in chapter 3 · 100 XP · 3 objectives checked by tests

Topics covered: Route groupPrefixAnonymous function

The couriers' app and the depot board have their URLs all mixed together. Margot would like to put everything the app uses under /api, as in the Laravel projects she has seen.

Your mission

  1. In routes/web.go, create a route group with the /api prefix.
  2. Move the three delivery routes into it: GET /api/deliveries, GET /api/deliveries/{id} and POST /api/deliveries.
  3. The old URLs, /deliveries…, no longer exist. /ping, /couriers and /board stay where they are. (Goravel also has a routes/api.go, which this course's skeleton doesn't use: everything stays in routes/web.go.)

Reminder

Prefix("/api").Group(…) is Laravel's Route::prefix('api')->group(…). The group receives an anonymous function, written on the spot, which in turn receives a router: the routes declared on it get the prefix.

In Go, every package you use must be imported, and every import must be used: the compiler refuses both mistakes. route.Router is a type from Goravel's contracts/route package, so it has to be added to the imports.