Last active
August 29, 2015 14:13
-
-
Save benjaminjackman/04222754ba41512aa794 to your computer and use it in GitHub Desktop.
This file contains 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
//This is my general purpose client for the Javascript side | |
class AutowireClientAjax(val url: String)(implicit val ec: ExecutionContext = JSExecutionContext.queue) | |
extends SerAutowireClient { | |
override def doCall(req: Request): Future[Any] = { | |
val r = AutowireHelp.ClientSideReq.fromAutowire(req) | |
Ajax.post( | |
url = url, | |
data = r.toJsonCompact() | |
).map(_.responseText) | |
} | |
} |
This file contains 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
trait RestApi { | |
val stopWordsDB: StopWordsDB | |
val corpusDB: CorpusDB | |
val rawWordsDB: WordsDB | |
val filteredWordsDB: WordsDB | |
val rawStatsDB: CorpusStatsDB | |
val filteredStatsDB: CorpusStatsDB | |
} |
This file contains 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
class RestApiImpl(...) extends RestApi { | |
... implement trait methods in here | |
} |
This file contains 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
object AutowireServer extends autowire.Server[String, upickle.Reader, upickle.Writer] { | |
def write[Result: Writer](r: Result) = upickle.write(r) | |
def read[Result: Reader](p: String) = upickle.read[Result](p) | |
} |
This file contains 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
val apiImpl = new RestApiImpl(...) | |
//This requires a version of autowire that isn't or may not be released, you can experiment with it | |
//with this "biz.cgta" %% "autowire" % "0.2.7-M3" | |
val router = AutowireServer.innerRoute[RestApi](apiImpl) | |
post { | |
path("apis") { xs => | |
extract(_.request.entity.asString) { body => | |
respondWithHeaders( | |
RawHeader("Access-Control-Allow-Origin", "*"), | |
RawHeader("Access-Control-Allow-Headers", "Content-Type")) { | |
val r = (DESERIALIZE body TO autowire.Core.Request[???] WITH WHATEVER) | |
complete { | |
router(r) | |
} | |
} | |
} | |
} ~ path(Rest) { xs => | |
complete { | |
PRINT | "ERROR" | |
s"BAD PATH $xs" | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment