Skip to content

Instantly share code, notes, and snippets.

@rafi
Last active January 29, 2020 23:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rafi/8225054cdd500c90f14bd430abf90176 to your computer and use it in GitHub Desktop.
Save rafi/8225054cdd500c90f14bd430abf90176 to your computer and use it in GitHub Desktop.
Python 3 Falcon API example
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:])
version: '2'
services:
api:
build: .
image: myapp/api
container_name: myapp-api
ports:
- 8080:8080
volumes:
- .:/app
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