Servers
The HTTP server provides a simple request/response API. This gives you a lightweight way to build web applications or APIs.
serve_http(endpoint)
>>> website = """
... <html>
... <head>
... <style>
... body {
... font-family: courier;
... text-align: center;
... padding: 3rem;
... background: #111;
... color: #ddd;
... font-size: 3rem;
... }
... </style>
... </head>
... <body>
... <div>hello, world</div>
... </body>
... </html>
... """
>>> def hello_world(request):
... content = httpx.HTML(website)
... return httpx.Response(200, content=content)
>>> with httpx.serve_http(hello_world) as server:
... print(f"Serving on {server.url} (Press CTRL+C to quit)")
... server.wait()
Serving on http://127.0.0.1:8080/ (Press CTRL+C to quit)
Docs in progress...