Code suggested to be removed on Chapter 8: Controller


I have just downloaded the version 1.0.1 of the book and realized that in Chapter 8: Controllers, page 119, there is piece of code that is supposed to be removed from the routes.swift file however seems that is not the correct one as the route implemented is getAllHandler not the create acronym one as suggested. Is this correct? am I missunderstanding something?

Thank you very much for this awersome book :smiley:

Hey, just had a look and not quite sure I understand what you mean! :smile:

Having a look at it the book looks correct - it moves the getAllHandler (which is already in the AcronymsController) to a route group and then removes the remaining routes. That was originally set up on page 117. Does that make sense?

Hello Tim, sorry I think I did not explained myself properly.

At page 119 there are the following paragraphs:

RouteCollection requires you to implement boot(router:) to register routes. Add a new route handler after boot(router:):

func getAllHandler(_ req: Request) throws -> Future<[Acronym]> {
    return Acronym.query(on: req).all()

Then a few lines below:

This makes a GET request to /api/acronyms call getAllHandler(_:). You wrote this same route earlier in routes.swift. Now, it’s time to remove that one. Open routes.swift and delete the following handler:

   router.get("api", "acronyms") { req -> Future<Acronym> in
      return try req.content.decode(Acronym.self)
        .flatMap(to: Acronym.self) { acronym in
          return req)

As you see the second paragraph refers to getAllHandler(_:) however the chunk of code is the one used to create the Acronym. My understanding is that the chunk of code to be removed from routes.swift is:

router.get("api", "acronyms") { req ->e Future<[Acronym]> in
   return Acronym.query(on: req).all() 


Thank you very much again for the book and for your support :smiley:

@0xtim Do you have any feedback about this? Thank you - much appreciated! :]

I’ve just got to that part of the book and agree with @fjrivash - it looks incorrect to me too.

@vapor_matt @fjrivash yep you would be right! That’s a mistake, will get it fixed for the next release. Thanks!

when is the next release coming out @0xtim ?

We’re currently writing it and adding some extra chapters. Provisional date is start of next year, but it may change depending on releases of Vapor/Vapor Cloud etc