Search code examples
pythonapipython-3.xhug

Access HTTP PUT data in python hug


import hug

something = {'foo': 'bar'}

@hug.put('/')
def update_something():
    something['foo'] = <value_of_bar_from_http_put_request>

How do I access the put data so that I can update something? I looked up this and this but couldn't find anything.


Solution

  • import hug
    
    something = {'foo': 'bar'}
    
    @hug.put()
    def update_something(bar: hug.types.text):
        something['foo'] = bar
        return something  # may be
    

    And then you may use requests to test

    import requests
    
    print(requests.put('http://localhost:8000/update_something',
        data={'bar': 'foobar'}).json())