Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

creating a minimal HTTP server with asyncio

While I'm familiar with both HTTP servers and event loops, I'm having some trouble grasping the inner workings of Python's asyncio.

As a learning exercise, I've been trying to write a minimal HTTP server (just echoing out the request method, URI, headers and body), without additional dependencies. I've looked into aiohttp and aiowsgi for reference, but having trouble understanding what's going on there - in part because the perceived complexity of protocols, transports etc. is a bit overwhelming. So I'm currently stuck because I don't quite know where to begin.

Is it naive to expect this to be just a few lines of code to establish the connection, consume the incoming text stream and send back another text stream?

like image 686
AnC Avatar asked Dec 21 '14 10:12

AnC


1 Answers

You can take a look on picoweb as example of very simple (and very limited) HTTP server.

But, sure, when you'll try to implement full-feature web server you will get something like aiohttp -- HTTP is complex (even maybe complicated) standard.

like image 153
Andrew Svetlov Avatar answered Sep 20 '22 11:09

Andrew Svetlov