Ask Documentation
WebsiteGitHubPyPI
  • Introduction
  • Getting Started
    • Install & Get Started
    • Hello, World!
  • Routes & Requests
    • Routes
    • Defining Routes
    • Request Data
    • HTTP Status Codes & Methods
    • CORS
  • Response
    • JSON Response
    • JSON Response With an HTTP Status Code
  • Classes
    • Class Instance Variable
    • Initialization/Constructor Method
  • Data Types
    • Dictionaries
  • Built-in Utilities
    • Quick_set()
    • Deep()
    • Serialize()
    • Require_keys()
    • Random Generators
    • Pattern Matching
    • Email
  • Database
    • Ask and Databases
    • Models/Classes
      • Columns
      • Initialization/Constructor
      • Serialization
      • The &basic decorator
    • CRUD
      • Add
      • Select
      • Update
      • Delete
    • Check if a Row Exists
    • Sorting
    • Database Lists
  • JWT Authentication
    • Introduction
    • Protecting Routes
    • How to Create a Basic Login System
    • Properties & Methods of _auth
    • Making Requests to Protected Routes
  • Decorators
    • What are Decorators?
    • Create and Use Custom Decorators
    • Built-in Decorators
  • Security
    • Hashing
    • Route Security
    • Environment Variables
  • Configuring the Transpiler
  • Askfile.toml
  • Modules & Libraries
    • Importing an Ask Module
    • Includes
    • Importing Python Modules
  • Development Tools
    • Editor Syntax Highlighting
    • Automatic API documentation
    • CLI Flags
    • Running in development mode
    • Versioning System
  • Contribute
    • Feature Requests
    • Bug Reports
    • Contribute Code
Powered by GitBook
On this page
  • Get Request Data
  • Helpful Functions For Working With Request Data
  • require_keys()
Export as PDF
  1. Routes & Requests

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.

Get Form Data

form
  • Returns a dictionary.

Get Query Parameters

args
  • Returns a dictionary.

Get Files

files
  • Returns a dictionary.

All Request Data in One Dictionary

req
  • Returns a dictionary.

  • Combines body, form, and args into one 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!')
    # ...
PreviousDefining RoutesNextHTTP Status Codes & Methods

Last updated 3 years ago