Created
September 25, 2018 15:19
-
-
Save Morabaraba/29102a86ee182ae4d1d6d61b3c6526a9 to your computer and use it in GitHub Desktop.
modified `hello.py` [connexion](https://github.com/zalando/connexion/) example to include `Accept` header validation decorator.
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
#!/usr/bin/env python3 | |
import connexion | |
import flask | |
from decorator import decorator | |
@decorator | |
def requires_header(f: callable, *args, **kwargs): | |
accept = flask.request.headers.get('Accept') | |
print(accept) | |
if not accept or accept != 'application/xml': | |
return '400', 400 | |
return f(*args, **kwargs) | |
def post_greeting(name: str) -> str: | |
return 'Hello {name}'.format(name=name) | |
@requires_header | |
def get_user() -> str: | |
return 'got user' | |
if __name__ == '__main__': | |
app = connexion.FlaskApp(__name__, port=8080, specification_dir='swagger/') | |
app.add_api('helloworld-api.yaml', arguments={'title': 'Hello World Example'} ) #, validate_responses=True)# strict_validation=True) | |
app.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment