Last active
January 29, 2020 23:10
-
-
Save rafi/8225054cdd500c90f14bd430abf90176 to your computer and use it in GitHub Desktop.
Python 3 Falcon API example
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
import sys | |
import signal | |
import falcon | |
class HealthResource: | |
def on_get(self, req, resp): | |
resp.media = {'status': 'OK', 'health': 1.0} | |
def sigterm_handler(signum, frame): | |
sys.exit(1) | |
def main(args): | |
from wsgiref import simple_server | |
signal.signal(signal.SIGTERM, sigterm_handler) | |
httpd = simple_server.make_server('0.0.0.0', 8080, api) | |
httpd.serve_forever() | |
api = falcon.API() | |
api.add_route('/healthz', HealthResource()) | |
if __name__ == '__main__': | |
main(sys.argv[1:]) |
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
version: '2' | |
services: | |
api: | |
build: . | |
image: myapp/api | |
container_name: myapp-api | |
ports: | |
- 8080:8080 | |
volumes: | |
- .:/app |
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
FROM python:3.7-slim | |
RUN pip install --no-cache-dir falcon | |
ENTRYPOINT ["python", "app.py"] | |
WORKDIR /app | |
COPY . . |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment