Noggin: A simple web framework that will run on your esp8266 boards.
Posted: Wed Nov 15, 2017 10:29 pm
I was asking the other day (viewtopic.php?f=2&t=4036) about minimal http servers for MicroPython, but I didn't get any responses and I wasn't able to find anything suitable...so I've written my own, and I've made it available in case someone else finds it useful:
https://github.com/larsks/micropython-noggin
It supports both "Expect: 100-continue" headers from clients and chunked encoding, which means it will interoperate nicely with e.g., "curl".
It uses a simple and hopefully not surprising interface for mapping request URIs to functions using regular expressions, and it maps match groups in your routes to positional parameters in your functions:
I've tried as much as possible to use memory-efficient i/o, so that you can serve and receive large files without running out of memory.
There is some simple demonstration code available at https://github.com/larsks/micropython-n ... es/demo.py that shows off most of the features. There is a slightly more involved demo available at https://github.com/larsks/micropython-n ... fileops.py that implements a simple http fileserver, with support for getting, putting, renaming, and deleting files. It also provides access to filesystem, memory, and network configuration information.
I'm running this on a Wemos D1 mini (clone), https://wiki.wemos.cc/products:d1:d1_mini, where it seems to be working fine so far.
https://github.com/larsks/micropython-noggin
It supports both "Expect: 100-continue" headers from clients and chunked encoding, which means it will interoperate nicely with e.g., "curl".
It uses a simple and hopefully not surprising interface for mapping request URIs to functions using regular expressions, and it maps match groups in your routes to positional parameters in your functions:
Code: Select all
from noggin import Noggin
app = Noggin()
@app.route('/')
def index(request):
return 'Here is some content for you'
@app.route('/doc/([^/]+)')
def get_doc(request, docid):
if docid in documents:
return documents[docid]
else:
raise HTTPError(404)
app.serve()
There is some simple demonstration code available at https://github.com/larsks/micropython-n ... es/demo.py that shows off most of the features. There is a slightly more involved demo available at https://github.com/larsks/micropython-n ... fileops.py that implements a simple http fileserver, with support for getting, putting, renaming, and deleting files. It also provides access to filesystem, memory, and network configuration information.
I'm running this on a Wemos D1 mini (clone), https://wiki.wemos.cc/products:d1:d1_mini, where it seems to be working fine so far.