API request and response decorators
So far we have been primarily focused on decorating controllers, so the Nest.js swagger module can build a swagger document containing all of the inputs our APIs expect or could use. The Nest.js swagger module also contains decorators that can be used to describe with what and how APIs respond and the format of the content it expects to receive and send. These decorators help form a complete picture of how a specific API works when looking at the swagger document or when using the swagger UI.
All of the APIs we have covered in our example blog application follow a typical modal of accepting inputs in the form of JSON. However, it is possible that an application may need to take a different input type, often referred to as a MIME type. For example, we could allow users of our example blog application to upload an avatar image. An image cannot easily be represented as JSON so we would need to build an API that takes an input MIME type of image/png
. We...