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.create
  • put /api/1.0/person/:personid personcontroller.update
  • get /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

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -