AnC
AnC

Reputation: 4201

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?

Upvotes: 12

Views: 12999

Answers (1)

Andrew Svetlov
Andrew Svetlov

Reputation: 17386

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.

Upvotes: 9

Related Questions