Skip to content

Instantly share code, notes, and snippets.

@erickpeirson
Last active April 25, 2019 20:28
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 erickpeirson/9e10ef4bdae342e8d597565df8b7379d to your computer and use it in GitHub Desktop.
Save erickpeirson/9e10ef4bdae342e8d597565df8b7379d to your computer and use it in GitHub Desktop.
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "http://foo.qwerty/some/schema#",
"title": "A Resource",
"type": "object",
"properties": {
"thiskeyhere": {
"type": "string"
},
"aninteger": {
"type": "integer"
},
"etc": {
"type": "boolean"
}
}
}
from flask import Flask, Response, jsonify
from mypy_extensions import TypedDict
from .somewhere import datastore
app = Flask(__name__)
class AResource(TypedDict):
thiskeyhere: str
aninteger: int
etc: bool
# See `schemas/aresource.json` for a JSON schema...
@app.route('/some/resource/<resource_id>', methods=['GET'])
def get_some_resource(resource_id: str) -> Response:
"""Get a resource, and do it with style."""
resource: AResource = datastore.load_resource(resource_id)
return jsonify(resource) # type: Response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment