Last active
March 1, 2016 17:21
-
-
Save jonvuri/fb0a6501361102887821 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case class Color(value: String, name: String) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import io.circe.jawn._ | |
import io.circe.generic.auto._ | |
object ColorService { | |
class ColorServiceHandler { | |
// colorTable provided as private var | |
def postColor(request: HttpServiceRequest, responder: HttpServiceResponder) { | |
lazy val requestBody = Bytes.toString(request.getContent) | |
decode[Color](requestBody).fold( | |
{ error => responder.sendError(400, error.getMessage) }, | |
{ color => colorTable.write(color.name, color) } | |
) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment