hug icon indicating copy to clipboard operation
hug copied to clipboard

POST handling hug.types.text?

Open arjenpdevries opened this issue 7 years ago • 1 comments

I want to POST a textarea value to a hug-based service. This works fine:

@hug.post('/api/card')
@hug.local()
def birthday_card(body):
    """Receive birthday card"""
    return {'message': '{0}'.format(body[0])}

But if I declare the input to be of type hug.types.text using

def birthday_card(body:hug.types.text):

the textarea value raises an error "Incorrect text value" and does not get interpreted correctly, returning

{
    "errors": {
        "body": "Invalid text value provided"
    }
}

(I think this worked before I upgraded ubuntu, python and hug, but am unfortunately not 100% sure.)

The relevant form bit:

<textarea name="body" form="card" rows="5" cols="40">
Happy birthday to you
Happy birthday to you
Happy birthday Dear To-o-m
Happy birthday to you
</textarea>
<form action="/api/card" method="post" id="card"> 
Call API: 
<input type="submit" name="body" value="Card" />
</form>

arjenpdevries avatar Nov 08 '18 14:11 arjenpdevries

Hi @arjenpdevries; You can send JSON to the POST endpoint; So, if you have this JSON:

{
	"textarea": "Heya! Have you read the docs already?"
}

You could send it to a endpoint like that:

@hug.post('/api/card')
@hug.local()
def birthday_card(textarea:hug.types.text):
    """Receive birthday card"""
    return {'message': textarea}

JGabrielGruber avatar Apr 10 '19 23:04 JGabrielGruber