I created a very simple project that shows how to do this:
https://github.com/jamesward/playscalapython
It's not that much. Here is the game! / Scala application:
package controllers
import play._
import play.mvc._
object Application extends Controller {
def index = {
val widget1: Widget = Widget(1, "The first Widget")
val widget2: Widget = Widget(2, "A really special Widget")
val widget3: Widget = Widget(3, "Just another Widget")
val widgets: Vector[Widget] = Vector(widget1, widget2, widget3)
Json(widgets.toArray)
}
}
case class Widget(val id: Int, val name: String)
Here is a Python application that consumes JSON from Play! Application:
import os
import simplejson
import requests
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
jsonString = requests.get(os.environ.get("JSON_SERVICE_URL", "http://localhost:9000"))
widgets = simplejson.loads(jsonString.content)
htmlResponse = "<html><body>"
for widget in widgets:
htmlResponse += "Widget " + str(widget['id']) + " = " + widget['name'] + "</br>"
htmlResponse += "</body></html>"
return htmlResponse
if __name__ == "__main__":
port = int(os.environ.get("PORT", 5000))
app.run(host='0.0.0.0', port=port)
source
share