belyalov / tinyweb

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

Add ability to pass some arguments to RESTful handler #10

Closed belyalov closed 6 years ago

belyalov commented 6 years ago

Currently, there is no way to pass additional parameters into restful handler:

class rest():
    def put(self, data):
        # .. no way to distinguish between URIs

# Use one handler to handle 2 different URIs 
web.add_resource(rest, '/api1')
web.add_resource(rest, '/api2')

Proposed way is to add ability to pass any additional keyword args **kwargs:

class rest():
    def put(self, data, type):
        if type == 1:
            # do something for first case
        else:
            # second case

# Use one handler to handle 2 different URIs 
web.add_resource(rest, '/api1', type=1)
web.add_resource(rest, '/api2', type=2)