I am trying my hands on with Finch. New to scala and Finch I Would to know how to create and test a file upload service. aim - to upload the file and read the contents of file
import java.nio.file.{Files, Paths}
import com.twitter.util.{Await, Future}
import com.twitter.finagle.{Http, Service}
import com.twitter.finagle.http.{Request, RequestBuilder, Response, Status}
import com.twitter.io.{Buf, Charsets}
import com.twitter.finagle.http.exp.Multipart.FileUpload
import io.finch._
//import io.finch.test.ServiceIntegrationSuite
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.scala.DefaultScalaModule
object FinchDemO {
//libraryDependencies ++= Seq("com.github.finagle" %% "finch-core" % "0.13.0")
val mapper: ObjectMapper = new ObjectMapper().registerModule(DefaultScalaModule)
//Endpoint for http://localhost:8080/helloO
val api: Endpoint[String] = get("helloO") {
Ok("Hello, World!")
} //handle { case e: ArithmeticException => BadRequest(e) }
val upload: Endpoint[String] = post("upload" :: fileUpload("file")) {
file: FileUpload => Ok("Success")
}
val server = Http.server.serve("localhost:8080", upload.toServiceAs[Text.Plain])
Await.ready(server)
}