belyalov / tinyweb

Simple and lightweight HTTP async server for micropython
MIT License
239 stars 40 forks source link

Support for multiple params in url and added method to obtain query string as dictionary #51

Open Beormund opened 1 year ago

Beormund commented 1 year ago

Adds ability to specify multiple parameter names

@app.resource('/cmnd/<device>/<state>')
def cmndstate(data, device, state):
    return {'device':  device, 'state':  state}

Adds ability to obtain query string as a dictionary from request object.

@app.route('/cmnd')
async def cmnd(request, response):
    d = request.read_parse_query_data()
    await response.start_html()
    await response.send(f"<html><body><h1>{d}</h1></body></html>")
Beormund commented 1 year ago

It looks like we could get away with storing just the parameter count in params['_param_names']. I can't see the param names being used anywhere else. Perhaps change this to params['_param_count']. It could then be used to pass the correct number of arguments to the user's route function.