Skip to content

Instantly share code, notes, and snippets.

@kennethreitz
Created October 10, 2018 11:54
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 kennethreitz/716ff444a51b54a69027fd77811587e1 to your computer and use it in GitHub Desktop.
Save kennethreitz/716ff444a51b54a69027fd77811587e1 to your computer and use it in GitHub Desktop.
import responder
import graphene
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello_world():
return "Hello, World from flask!"
api = responder.API()
api.mount("/hello", app)
@api.route("/")
def hello(req, resp):
# resp.status = responder.status.ok
resp.content = api.template("test.html")
class ThingsResource:
def on_request(self, req, resp):
resp.status = responder.status.HTTP_200
resp.media = ["yolo"]
class Query(graphene.ObjectType):
hello = graphene.String(name=graphene.String(default_value="stranger"))
def resolve_hello(self, info, name):
return "Hello " + name
schema = graphene.Schema(query=Query)
# Alerntatively,
api.add_route("/graph", schema)
print(
api.session()
.get(
"http://app/graph",
data="{ hello }",
headers={"Accept": "application/x-yaml"},
# data="hello",
)
.text
)
# print(
# api.session()
# .get(
# "http://app/hello/",
# data="{ hello }",
# headers={"Accept": "application/x-yaml"},
# # data="hello",
# )
# .text
# )
# {hello: Hello stranger}
# api.run(port=5000, expose_tracebacks=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment