Created
April 4, 2017 21:58
-
-
Save rockwotj/93a9edd5c25cba06f71bf3dd9228ba2d to your computer and use it in GitHub Desktop.
The HTTP GCF example from https://cloud.google.com/functions/docs/writing/http but in scalajs
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
package com.google.functions.examples.scalajs | |
import scala.scalajs.js.annotation._ | |
import scala.scalajs.js | |
import js.DynamicImplicits._ | |
@js.native | |
trait Request extends js.Any { | |
val body: js.Dictionary[Any] = js.native | |
} | |
@js.native | |
trait Response extends js.Any { | |
def status(code: Int): Response = js.native | |
def send(body: String): Response = js.native | |
def end(): Response = js.native | |
} | |
object MyFunctions { | |
@JSExportTopLevel("helloWorld") | |
def helloWorld(req: Request, res: Response): Unit = { | |
req.body.get("message") match { | |
case Some(str: String) => | |
println(s"Function called with message: '$str'") | |
res.status(200).end() | |
case _ => | |
res.status(400).send("There was no message defined!") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment