HomeToolsAbout a20k

DTO

What is it

Structure or classes used to represent data being transferred between different parts of a system or between systems

Illustration

Protofile definition for a user creation process in a system

// User DTO message User { int32 user_id = 1; string name = 2; repeated string addresses = 3; bool is_active = 4; UserType user_type = 5; } // UserType enum which is used in user DTO enum UserType { REGULAR = 0; PREMIUM = 1; } // Service definition that accepts a user DTO and returns a user DTO service UserService { rpc createUser(User) returns (User); }

In above, we have User DTO, which is used to create a user using the createUser method of UserService

  • When a protoc compiler reads this proto file, it will create:
    • a DTO class named User
    • a service class named UserService
    • an enum UserType
© VincentVanKoh