Last active
April 25, 2019 20:28
-
-
Save erickpeirson/9e10ef4bdae342e8d597565df8b7379d to your computer and use it in GitHub Desktop.
This file contains 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
{ | |
"$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" | |
} | |
} | |
} |
This file contains 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
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