Creating a middleware

You might be wondering what is a middleware? Middleware is very similar to a route handler as it gets passed a request and needs to return a response object. You can layer multiple middleware on a single or multiple routes and these middleware are invoked before our controller code is executed. So, you can do some preprocessing on the request before forwarding the same request forward to the controller. The response we get from the controller can also be modified inside of a middleware function before sending it back to the user. This is exactly what we want to do, and that is to let our middleware forward the request to the ShoppingListController and the ItemController so that it can generate a response first. Then, ...

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.