-
Notifications
You must be signed in to change notification settings - Fork 35
Query parameters
Query parameters are name-value pairs sent as part of the request URL following ?
character.
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.
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');
}
queryParams
is of type QueryParams
, which is extended from DynamicDottableMap
. This offers some nice features like:
- Type conversion
- Query parameters as properties
DynamicDottableMap
provides convenience methods to convert query parameter value to built-in type.
-
get
Returns query parameter asString
-
getInt
Converts and returns query parameter asint
-
getDouble
Converts and returns query parameter asdouble
-
getNum
Converts and returns query parameter asnum
-
getBool
Converts and returns query parameter asbool
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);
}
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
- Route handler
- Path matching
- Path parameters
- Query parameters
- Serving static files
- Cookies
- Controller
- Parameter binding
- Hot reload
Serialization
Forms
Sessions
Authentication
- Basic authentication
- Form authentication
- JSON authentication
- Authorization
- OAuth
- MongoDb
- PostgreSQL
- MySQL
- Establish connection
- ORM
- Server sent events (SSE)
- Websockets
- systemd
- Docker
- AppEngine