Request Data

How to read and handle request data.

There are a few built-in variables and functions accessible in routes, for reading, verifying and working with request data.

Get Request Data

Get the JSON body of a request.

body
  • Returns a dictionary.

Helpful Functions For Working With Request Data

require_keys()

Not specifically for requests, this function can be used in other circumstances.

Takes in two parameters: a list of keys to check for, and a dictionary (e.g. body).

# Verify that the request's JSON body contains all required parameters.
@post('/note'):
    if require_keys(['title', 'text'], body):
        # Not all required keys where found
        status('Please provide all required parameters.', 400)
    
    # All keys where found
    print('Sucess!')
    # ...

Last updated