Skip to content

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

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