Skip to content

Instantly share code, notes, and snippets.

@gilsondev
Created October 25, 2015 14:12
Show Gist options
  • Save gilsondev/441fa154e97fb062d249 to your computer and use it in GitHub Desktop.
Save gilsondev/441fa154e97fb062d249 to your computer and use it in GitHub Desktop.
Resource class with Falcon Framework
# -*- coding: utf-8 -*-
import falcon
try:
import ujson as json
except Exception as e:
import json
class LeroleroResource:
def on_get(self, req, resp):
"""Retorna um dicionario qualquer"""
minha_frase = {
'frase': "Acima de tudo, e fundamental ressaltar que bla bla bla",
'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