Skip to main content

Define a DTO

Bitloops language is built from the ground up using software engineering principles and best practices. DTOs allow you to better encapsulate data and carry it between independent parts of the system.

In Bitloops Language you simply define a DTO:

DTO <identifier name with a DTO suffix> { parameters list separated with semicolon } .

Parameters in DTOs are written in the following format:

[optional] parameterType parameterName;

As you can see, it is possible to make a parameter optional by placing the word optional in front of it.

Below is an example of DTOs in action.

DTO ExampleRequestDTO {
  string name;
  optional string surname;
}
DTO HExampleResponseDTO {
  string message;
}

By default, all parameters are required (unless optional is used in front) and errors will be thrown in the controllers if parameters are missing.

To learn more about DTOs, read our reference guide on DTOs