Beispiel #1
0
    def on_put(self, req, resp, article_uuid):
        """Update an article with url params using PUT"""

        # .decode() seems mandantory when running this in python3
        # See: http://stackoverflow.com/questions/6862770/python-3-let-json-object-accept-bytes-or-let-urlopen-output-strings
        req_body = json.loads(req.stream.read().decode('utf-8'))
        title = req_body['title']
        subtitle = req_body['subtitle']
        body = req_body['body']

        if title: blog.update_article(article_id=article_uuid, title=title)
        if subtitle: blog.update_article(article_id=article_uuid, subtitle=subtitle)
        if body: blog.update_article(article_id=article_uuid, body=body)

        resp.body = json.dumps(blog.fetch_article(article_id=article_uuid))
        resp.status = falcon.HTTP_200
Beispiel #2
0
 def on_get(self, req, resp, article_uuid):
     """GET a specific article"""
     resp.body = json.dumps(blog.fetch_article(article_id=article_uuid))
     resp.status = falcon.HTTP_200