jczic / MicroWebSrv

A micro HTTP Web server that supports WebSockets, html/python language templating and routing handlers, for MicroPython (used on Pycom modules & ESP32)
https://github.com/jczic/MicroWebSrv
MIT License
641 stars 116 forks source link

added decorator for adding a handler function to the route list #14

Closed JK-de closed 6 years ago

JK-de commented 6 years ago

Instead of:

def _httpHandlerTestGet(httpClient, httpResponse):
    pass

routeHandlers = [( "/test", "GET", _httpHandlerTestGet)]

MicroWebSrv(routeHandlers=routeHandlers)

You can use the decorator before the handler function:

@MicroWebSrv.route('/test')
def _httpHandlerTestGet(httpClient, httpResponse):
    pass

MicroWebSrv()

Additional you can also use the 'old' way

jczic commented 6 years ago

Thank you Jochen Krapf, I've merged your decorator system for the routes :) It's cool !