Doing scala client for REST service and following Scala semantics. Based on Swagger -
we using swagger rest api definition, declaration , client code generation.
i have few concerns. imagine have entity person , associated rest endpoints:
post /api/1.0/person
personcontroller.createput /api/1.0/person/:personid
personcontroller.updateget /api/1.0/person/:personid
personcontroller.get
i use play , swagger annotations annotate personcontroller.create, accepts case class instance person definition.
sealed case class personcreate(lastname:string, firstname:string, address:option[string] = none)
semantics clear. api user must provide firstname , lastname, address optional.
then exiting part starts. need 1 more case class describe person:
sealed case class personview(id:long, lastname:string, firstname:string, address:option[string] = none)
when person entity created gets identifier (surrogate key db)
and need 1 more case class represents update:
sealed case class personupdate(id:long, lastname:option[string], firstname:option[string], address:option[string] = none
my rest user autogenerated scala client like:
class personrestservice(url:string) { def create(person : personcreate)= {...} def update(person : personupdate)= {...} def get(id:long) : personview = {...} }
i following scala case class semantics , exposing contract using case class definitions becomes complex. approaches simplify it?
my idea define optional fields , put validation routines client code.
Comments
Post a Comment