Cosmo is an asynchronous python webserver that utilizes raw sockets to send and receive data, without using ASGI/WSGI.
from cosmo import App, Request, Response
app = App("0.0.0.0", 8080)
@app.route("/", "text/html")
async def index(request: Request):
return Response(f"<h1>{request.address}</h1>")
app.serve()
from cosmo import App, Request, Response
app = App("0.0.0.0", 8080)
@app.route("/", "text/html")
async def index(request: Request):
headers = {"x-custom-header": "custom"}
content = "<h1>Custom Headers: </h1>\n<ul>"
for header in headers.keys():
content += f"<li>{header}: {headers[header]}</li>\n"
content += "</ul>"
return Response(content, headers)
app.serve()
from cosmo import App, html_page, Request, Response
app = App("0.0.0.0", 8080)
@app.route("/", "text/html")
async def index(request: Request):
return Response(html_page("path/to/page.html"))
app.serve()
In router.py
:
from cosmo import Request, Response, Router
router = Router()
@router.route("/")
async def index():
return Response("<h1>Hi</h1>")
In app.py
:
from cosmo import App, Request, Response
from router import router
app = App("0.0.0.0", 8080)
app.import_router(router)
app.serve()
Coming soon...