Skip to content

Instantly share code, notes, and snippets.

@kurozumi
Created July 10, 2016 02:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kurozumi/2cb1a8c1bca2e58662da367ffbc31b24 to your computer and use it in GitHub Desktop.
Save kurozumi/2cb1a8c1bca2e58662da367ffbc31b24 to your computer and use it in GitHub Desktop.
【Python】Bottleを使ってJSON形式のレスポンスを返すサンプル
from bottle import route, run, HTTPResponse
import os
@route("/sample.json")
def json():
body = {"status": "OK", "message": "hello world"}
r = HTTPResponse(status=200, body=body)
r.set_header("Content-Type", "application/json")
return r
run(host="0.0.0.0", port=int(os.environ.get("PORT", 5000)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment