Bootstrapping a web server in Scala

后端 未结 8 1786
走了就别回头了
走了就别回头了 2021-02-01 10:32

The following is possible using Python:

$ apt-get install python
$ easy_install Flask
$ cat > hello.py
from flask import Flask
app = Flask(__name__)

@app.rou         


        
8条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-01 10:47

    As David Winslow mentioned, Unfiltered usage code snippet

    INFO: Simple API capabilities for Apache Spark word count example written in Scala using Unfiltered.

    object SimplePlan extends Plan {
      def intent = {
      case req @ GET(Path("/get")) => {
        Ok ~> ResponseString(WordCount.count("Test #1: Test the Default word count program").mkString("\n"));
      }
    
      case req @ POST(Path("/get_custom")) => {
        val custom_string = Body.string(req)
        Ok ~> ResponseString(WordCount.count(custom_string).mkString("\n"))
      }
     }
    }
    
    object SimpleServer extends App {
      val bindingIP = SocketPortBinding(host = "localhost", port = 8080)
      unfiltered.jetty.Server.portBinding(bindingIP).plan(SimplePlan).run()
    }
    

    Complete example is here

提交回复
热议问题