-
Notifications
You must be signed in to change notification settings - Fork 35
Route handler
Ravi Teja Gudapati edited this page Dec 26, 2017
·
25 revisions
A Route handler is a function or method that processes an incoming HTTP Request
and sends back the resulting Response
.
To achieve this, the prototype of route handler is of the form:
typedef FutureOr<dynamic> RouteFunc(Context ctx);
The Context
encapsulates the entire context of a HTTP request. Among other things, it contains the Request
object of the current HTTP request as member req
.
Note that the return type of the route handler is not dynamic
as opposed to the expected Response
. This is because, in cases where the return value is not Response
, Jaguar will automatically build a Response
object from the returned value.
Here is an example of adding a simple route handler function to Jaguar server at route path /hello
:
import 'package:jaguar/jaguar.dart';
main() async {
final server = new Jaguar(); // Serves the API at localhost:8080 by default
// Add a route handler for 'GET' method at path '/hello'
server.get('/hello', (Context ctx) => 'Hello world!');
await server.serve();
}
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