Skip to content

Instantly share code, notes, and snippets.

@lancewalton
Created June 18, 2015 13:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lancewalton/aa2811e0823ffaf93387 to your computer and use it in GitHub Desktop.
Save lancewalton/aa2811e0823ffaf93387 to your computer and use it in GitHub Desktop.
case class Document(id: String, contentType: String, content: Array[Byte])
object Server {
def apply() = {
val service = HttpService {
case req @ POST -> Root / "document" / id => upload(req, id)
}
JettyBuilder
.bindHttp(8080)
.mountService(service, "/")
}
private def upload(req: Request, id: String) = {
// I want to do something here that results in a call to store(document)
// document.id is given by the id parameter
// document.contentType is given by req.contentType and it is required
// document.content is given by the request body
}
private def store(document: Document) = {
// Side effecting stuff that writes the document somewhere
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment