How to pass a large string to an HTTP API?

What I’m trying to do:

I have created an API using the built in HTTP API module. The API extracts keywords from a text, and returns the extracted keywords to the caller.

Currently, the only way I can figure out to pass the text to the API is by adding it to the end of the querystring, such as

import requests
response = requests.get(" text to parse")

However, I would like to be able to pass a much larger string/block of text as an argument instead of tacking it on to the end of the querystring/url. How can I accomplish this? Does the Anvil API module accept those sorts of parameters?

What I’ve tried and what’s not working:

Code Sample:

# this is a formatted code snippet.
# paste your code between ``` 

Clone link:
share a copy of your app

Some people in this situation would convert your text to something like a base64 encoder/decoder. (For the large text portion of the data, possibly compressed)

When you use GET you usually add the payload, just a few strings, to the query string.

When you use POST you usually use the data argument to add the payload.

Search for “payload” in this page and you will see some examples.


Use POST, because GET is often limited to a payload of a few Kilobytes. If POST is limited in size, it’s typically at least a few Megabytes.

In your HTTP endpoint function, GET values are typically handled in some way similar to this, where (**params) contains the query parameters):

@anvil.server.http_endpoint('/parsegetvalues', enable_cors=True)
def parsegetvalues(**params):
  return {'id': new_row.get_id()}

POST values are typically handled something like this, where anvil.server.request.body_json[‘somekey’] contains the values:

@anvil.server.http_endpoint('/parsepostvalues', enable_cors=True)
def parsepostvalues(**params):
  return {'id': new_row.get_id()}
1 Like