scala - Custom Response from Controller in Finatra -
in app have custom case class below bunch of additional fields.
case class user(id: uuid, username: string, password: string)
now finatra controller picks response returned service , sends json response contains password hash well. controller basic gets
get("/users") {request: getusersrequest => userservice.users() }
so question how customize response such can drop password field , add additional data well.
assuming userservice.users()
returns list of users. i.e. list[user]
transform response map
.
for example, can map new case class.
case class userdto(id: uuid, username: string, comment: string)
you can map
tuple
if don't want use class yet.
get("/users") {request: getusersrequest => userservice.users().map(u => userdto(u.id, u.username, "comment!")) }
Comments
Post a Comment