From 555e9bff653ccef2220c61a4199845c187ce5eb6 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Sat, 30 Mar 2024 20:11:42 -0400 Subject: [PATCH] Add helloworld.py and update serve method in api.py --- examples/helloworld.py | 12 ++++++++++++ responder/api.py | 7 ++----- 2 files changed, 14 insertions(+), 5 deletions(-) create mode 100644 examples/helloworld.py diff --git a/examples/helloworld.py b/examples/helloworld.py new file mode 100644 index 0000000..4327e9d --- /dev/null +++ b/examples/helloworld.py @@ -0,0 +1,12 @@ +import responder + +api = responder.API() + + +@api.route("/{greeting}") +async def greet_world(req, resp, *, greeting): + resp.text = f"{greeting}, world!" + + +if __name__ == "__main__": + api.run() diff --git a/responder/api.py b/responder/api.py index 5a5cf4e..6b839d2 100644 --- a/responder/api.py +++ b/responder/api.py @@ -326,14 +326,13 @@ class API: """ return self.templates.render_string(source, *args, **kwargs) - def serve(self, *, address=None, port=None, debug=False, **options): + def serve(self, *, address=None, port=None, **options): """Runs the application with uvicorn. If the ``PORT`` environment variable is set, requests will be served on that port automatically to all known hosts. :param address: The address to bind to. :param port: The port to bind to. If none is provided, one will be selected at random. - :param debug: Run uvicorn server in debug mode. :param options: Additional keyword arguments to send to ``uvicorn.run()``. """ @@ -348,13 +347,11 @@ class API: port = 5042 def spawn(): - uvicorn.run(self, host=address, port=port, debug=debug, **options) + uvicorn.run(self, host=address, port=port, **options) spawn() def run(self, **kwargs): - if "debug" not in kwargs: - kwargs.update({"debug": self.debug}) self.serve(**kwargs) async def __call__(self, scope, receive, send):