Created
September 19, 2015 04:47
-
-
Save berlotto/a8ca1a44f86458985b2c to your computer and use it in GitHub Desktop.
RESTFul API example for blog post of http://blog.programadorlivre.com
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
# -*- encoding: utf-8 -*- | |
# RESTFul api test for blog post | |
# Author: Sérgio Berlotto <[email protected]> | |
# Site: http://blog.programadorlivre.com | |
# restapi.py | |
import falcon | |
try: | |
import ujson as json | |
except Exception, e: | |
import json | |
class LeroleroResource: | |
def on_get(self, req, resp): | |
"""Retorna um dicionário qualquer""" | |
minha_frase = { | |
'frase': "Acima de tudo, é fundamental ressaltar que a necessidade de renovação processual obstaculiza a apreciação da importância da gestão inovadora da qual fazemos parte.", | |
'autor': 'Gerador de LeroLero' | |
} | |
resp.body = json.dumps(minha_frase) | |
resp.set_header('Content-Type', 'application/json') | |
resp.content_type = "application/json" | |
api = falcon.API() | |
api.add_route('/frase', LeroleroResource()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment