Skip to content

Instantly share code, notes, and snippets.

@matlockx
Created August 10, 2014 11:10
Show Gist options
  • Save matlockx/eef375f29d1d8c31f854 to your computer and use it in GitHub Desktop.
Save matlockx/eef375f29d1d8c31f854 to your computer and use it in GitHub Desktop.
could not find implicit value for parameter marshaller
name := """short-url"""
version := "1.0"
scalaVersion := "2.11.2"
libraryDependencies ++= Seq(
"io.spray" % "spray-can" % "1.3.1" % "compile",
"io.spray" % "spray-routing" % "1.3.1" % "compile",
"com.typesafe.akka" %% "akka-actor" % "2.3.3"
)
package core
import akka.actor.ActorSystem
import spray.routing.{Route, SimpleRoutingApp, ValidationRejection}
import scala.concurrent.Future
import scala.util.Random
/**
*
*/
object ShortUrl extends App with SimpleRoutingApp {
implicit val actorSystem = ActorSystem("Short-Url")
startServer("0.0.0.0", 8080)(route)
implicit def executionContext = actorRefFactory.dispatcher
def getExampleBooleanResponse : Boolean = {
Random.nextBoolean()
}
def getExampleStringResponse : Option[String] = {
Some(Random.alphanumeric.take(7).mkString)
}
def route = Route {
path("shorten") {
post { ctx =>
val r = ctx.request.entity.asString
val f = Future(getExampleBooleanResponse)
f.mapTo[Boolean].map {
case true => ctx.complete {
s"http://localhost:8080/"
}
case _ => ctx.reject(ValidationRejection(s"Cannot save url $r"))
}
}
}~
path(Rest) { r =>
get { ctx =>
Future(getExampleStringResponse).mapTo[Option[String]].map {
case Some(result) => ctx.complete(result)
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment