ResponseRepresentable protocol

The final thing we need to do is make our Model ResourceRepresentable. As mentioned earlier in this chapter, the route handler needs to return a ResourceRepresentable object in order for Vapor to generate a Response object that gets sent back to the client who made the request. Luckily, the Vapor module has made it very easy for us to add this method simply by adding an extension on our Model, as follows:

extension ShoppingList: ResponseRepresentable { }

This line of code extends our ShoppingList Model to inherit all methods implemented by ResponseRepresentable. By default, the protocol requires the implementation of the makeResponse method that Vapor implements for us in the Model.swift class of the Vapor package. ...

Get Hands-On Full-Stack Development with Swift now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.