Skip to content

Query parameters

Ravi Teja Gudapati edited this page Jun 15, 2017 · 15 revisions

Introduction

Query parameters are sent as name-value pairs as part of the URL following the ?.

Example:

POST example.com/todo/1234?name=jaguar&message=hello&at=5

Query parameters are often used to send post/put data of the request. For example, HTML forms with simple inputs are usually encoded as query parameters.

Query parameters are also used to send extra parameters for the request.

Check the Query parameters section below for more information about how to obtain Query parameters using Jaguar.

Accessing Query parameters

queryParams method on Context object shall be used to obtain value of the query parameter by name.

Example:

  @Get(path: '/books')
  Future<Response<String>> getBooks(Context ctx) async {
    // get the queryParams from
    String from = ctx.queryParams.get('from');
  }

DynamicDottableMap

queryParams is of type QueryParams, which is extended from DynamicDottableMap. This offers some nice features like:

  1. Type conversion
  2. Query parameters as properties

Type conversion

DynamicDottableMap provides convenience methods to convert query parameter value to built-in type.

  • get
    Returns query parameter as String
  • getInt Converts and returns query parameter as int
  • getDouble Converts and returns query parameter as double
  • getNum Converts and returns query parameter as num
  • getBool Converts and returns query parameter as bool

All these methods take an optional defaultValue argument, which is returned if the conversion of the query parameter fails.

Example:

  @Get(path: '/books')
  Future<Response<String>> getBooks(Context ctx) async {
    // get the queryParams from
    int from = ctx.queryParams.getInt('from', 0);
  }

Query parameters as properties

DynamicDottableMap allows accessing query parameter values like they are properties on the queryParams object.

Example:

  @Put(path: '/book/:id')
  Future<Response<String>> updateBook(Context ctx) async {
    // get the query parameter as property
    String from = ctx.queryParams.from;
  }

Basics

Serialization

Forms

Sessions

Authentication

  • Basic authentication
  • Form authentication
  • JSON authentication
  • Authorization
  • OAuth

Database

Security

Real time

  • Server sent events (SSE)
  • Websockets

Deployment

  • systemd
  • Docker
  • AppEngine

API Documentation

Clone this wiki locally