-
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 of the request.
query
method on Context
object shall be used to obtain a query parameter by name.
server.get('/api/quote', (ctx) {
final int index = int.parse(ctx.queryParams['index']);
return quotes[index + 1];
});
Query parameters can be converted to one of the supported target types (int
, num
, double
and bool
) using one of the get*
methods.
server.get('/api/quote', (ctx) {
final int index = ctx.queryParams.getInt('index', 1);
return quotes[index + 1];
});
Query parameter index
is converted to int
using int.parse
function.
All these methods take an optional defaultValue
argument, which is returned if the conversion fails.
In the next article, we will learn how to serve static files using Jaguar.
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