Angel3 Developer Guide
  • README
  • Foreword
  • Tutorial
    • Getting Started
    • Minimal Setup
  • Command Line Interface
    • Setup
  • Templates and Views
    • Server Side Rendered Views
    • JAEL3
      • About
      • Basics
      • Custom Elements
      • Strict Resolution
      • Directive: declare
      • Directive: for-each
      • Directive: extend
      • Directive: if
      • Directive: include
      • Directive: switch
  • Authentication
    • About
    • Strategies
    • Local
  • Databases
    • Object Relational Mapping (ORM)
      • About
      • Basic Functionality
      • Relations
      • Migrations
      • PostgreSQL
    • NoSQL
  • Extensions and Plugins
    • Using Plug-ins
    • Writing a Plugin
  • Under the hood
    • Basic Routing
    • Requests & Responses
    • Request Lifecycle
    • Dependency Injection
    • Middleware
    • Controllers
    • Parsing Request Bodies
    • Serialization
    • Service Basics
    • Testing
    • Error Handling
    • Pattern Matching and Parameter
  • Angel Framework Migration
    • Angel 2.x.x to Angel3
      • Rationale - Why a new Version?
      • Framework Changelog
      • 3.0.0 Migration Guide
    • Angel 1.x.x to 2.x.x
      • Framework Changelog
      • 2.0.0 Migration Guide
  • Packages
    • Authentication
    • CORS
    • Database-Agnostic Relations
    • Configuration
    • Databases
      • ORM
      • MongoDB
      • JSON File-based
      • RethinkDB
    • Templates and Views
      • Jael template engine
      • Mustache Templates
      • compiled_mustache-based engine
      • html_builder-based engine
      • Markdown template engine
      • Using Angel with Angular
    • Hot Reloading
    • Pagination
    • Polling
    • Production Utilities
    • REST Client
    • Reverse Proxy
    • Router
    • Serialization
    • Service Seeder
    • Static Files
    • Security
    • Server-sent Events
    • shelf Integration
    • Task Engine
    • User Agents
    • Validation
    • Websockets
  • Resources
    • Dependency Injection Patterns
    • Example Projects
    • YouTube Tutorials
    • Ecosystem
Powered by GitBook
On this page
  • Requests and Responses
  • Return Values
  • Other Parameters
  • Queries, Files and Bodies
  • Next Up

Was this helpful?

  1. Under the hood

Requests & Responses

PreviousBasic RoutingNextRequest Lifecycle

Last updated 3 years ago

Was this helpful?

Requests and Responses

Angel3 is inspired by Express, and such, request handlers in general resemble those from Express. Request handlers can return any Dart object (see ). Basic request handlers accept two parameters:

  • - Contains vital information about the client requesting a resource, such as request method, request body, IP address, etc. The request object can also be used to pass information from one handler to the next.

  • - Allows you to send headers, write data, and more, to be sent to the client. To prevent a response from being modified by future handlers, call res.end() to prevent further writing.

Return Values

Request handlers can return any Dart value. Return values are handled as follows:

  • If you return a bool: Request handling will end prematurely if you return false, but it will continue if you return true.

  • If you return null: Request handling will continue, unless you closed the response object by calling . Some response methods, such as or automatically close the response.

  • A RequestHandler: the returned handler will be executed.

  • A Stream: toList will be called, and then returned.

  • A Future: it will be awaited, and then returned.

  • Anything else: Whatever other Dart value you return will be serialized as a response. The default method is to encode responses as JSON, using json.encode. However, you can change a response's serialization method by setting res.serializer = foo;. If you want to assign the same serializer to all responses, globally set on your Angel instance. If you are only returning JSON-compatible Dart objects, like Maps or Lists, you might consider injecting JSON.encode as a serializer, to improve runtime performance (this is the default in 2.0).

Other Parameters

Queries, Files and Bodies

You can access a mutable Map based on the URI query parameters by calling RequestContext.queryParameters.

For more information, see the API docs:

Next Up

Request handlers can take other parameters, instead of just a RequestContext and ResponseContext. Consult the .

Consult the to understand how to handle user input.

If you , be sure to use the lazy alternatives.

Now, let's learn about Angel3's .

body parsing documentation
write your own plugin
RequestContext
ResponseContext
Request Lifecycle
RequestContext
ResponseContext
res.close()
res.redirect()
res.serialize()
serializer
Requests and Responses
Return Values
Other Parameters
Queries, Files and Bodies
Next Up...
how they are handled
dependency injection documentation