Input Request
Last updated
Last updated
The input request is any input we'd expect from the client to send to our API. They can be in the form of URI parameters, headers, body content, and more.
A good way to know if something is an input request would be to just look at the Express documentation of all the req
properties.
The goal of this step is to know what exactly we'd expect from the client and to create some sort of contract between us, the server, and the client calling our RESTful API. To do so, we will use what are called Data Transfer Objects.
Data Transfer Objects (DTOs) are objects that carry and transform data in between processes. They are extremely useful when you want to customize properties of data that you want be exposed or hidden. They are objects that can create adapter-like layers in order to smoothly control the input and output flow of data between different function calls within your application.
In many other typed languages such as Java or C#, the built-in verbosity of those languages require you to type hint your input and output based on custom classes you would declare, making it easy to declare some sort of contract between the caller and callee.
In JavaScript land however, we do not have that, at least not in raw native JavaScript. This is why it is important to create some sort of DTO, so that we may not only create those contracts, but also create a self-documenting source of truth within our codebase. DTOs will be used heavily in our project in the upcoming chapters and will be illustrated as we get closer to looking at the code.