pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/encode/httpnext/blob/dev/docs/servers.md

rel="stylesheet" href="https://github.githubassets.com/assets/global-a40b6ece39d70d4a.css" /> httpnext/docs/servers.md at dev · encode/httpnext · GitHub
Skip to content

Latest commit

 

History

History
85 lines (71 loc) · 2.31 KB

File metadata and controls

85 lines (71 loc) · 2.31 KB

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 ahttpx
>>> website = """
...     <html>
...         <head>
...             <style>
...                 body {
...
...                     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)
>>> import httpx

>>> website = """
...     <html>
...         <head>
...             <style>
...                 body {
...
...                     text-align: center;
...                     padding: 3rem;
...                     background: #111;
...                     color: #ddd;
...                     font-size: 3rem;
...                 }
...             </style>
...         </head>
...         <body>
...             <div>hello, world</div>
...         </body>
...     </html>
... """

>>> 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 Requests  

pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy