Last active
August 29, 2015 14:22
-
-
Save prologic/4d4d23f0ca2f91531db8 to your computer and use it in GitHub Desktop.
A simple RESTful-ish Comments API based on the ReactJS Tutorial(s)
This file contains hidden or 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
from os import environ | |
from json import dumps, loads | |
from circuits.web import Server, Controller, Static | |
class Comments(Controller): | |
channel = "/comments.json" | |
def index(self, **data): | |
with open("comments.json", "r") as f: | |
comments = loads(f.read()) | |
if self.request.method == "POST": | |
comments.append({"author": data["author"], "text": data["text"]}) | |
with open("comments.json", "w") as f: | |
f.write(dumps(comments)) | |
self.response.headers["Content-Type"] = "application/json" | |
self.response.headers["Cache-Control"] = "no-cache" | |
return dumps(comments) | |
(Server(("0.0.0.0", int(environ.get("PORT", 3000)))) + Comments() + Static(docroot="public")).run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A simple RESTful-ish Comments API based on the ReactJS Tutorial(s)
See: https://github.com/reactjs/react-tutorial