12

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?

1 Answer 1

9

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks - that's quite close to what I was looking for. start_server in particular was the missing piece for me.
Sure. Trivial examples are good for learning. But as co-author of aiohttp I guess to use aiohttp.web for production code.
Nevermind, picoweb does not run on current CPython, with the last update two years ago - that's not useful.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.