# 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)`
httpx
```{ .python .httpx } >>> website = """ ... ... ... ... ... ...
hello, world
... ... ... """ >>> 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) ``` ```{ .python .ahttpx .hidden } >>> import httpx >>> website = """ ... ... ... ... ... ...
hello, world
... ... ... """ >>> async def hello_world(request): ... if request.path != '/': ... content = httpx.Text("Not found") ... return httpx.Response(404, content=content) ... content = httpx.HTML(website) ... return httpx.Response(200, content=content) >>> async with httpx.serve_http(hello_world) as server: ... print(f"Serving on {server.url} (Press CTRL+C to quit)") ... await server.wait() Serving on http://127.0.0.1:8080/ (Press CTRL+C to quit) ``` --- *Docs in progress...* --- ← [Clients](clients.md) [Requests](requests.md) →