Angel
2.x
2.x
  • Introduction
  • Migration from Angel 1.1.x
    • Rationale - Why a new Version?
    • Framework Changelog
    • 2.0.0 Migration Guide
  • ORM
    • About
    • Basic Functionality
    • Relations
    • Migrations
    • NoSQL
    • PostgreSQL
  • Guides
    • Getting Started
    • Basic Routing
    • Dependency Injection Patterns
    • Installation & Setup
    • Without the Boilerplate
    • Requests & Responses
    • Dependency Injection
    • Basic Routing
    • Request Lifecycle
    • Middleware
    • Controllers
    • Parsing Request Bodies
    • Using Plug-ins
    • Rendering Views
    • Service Basics
    • REST Client
    • Testing
    • Error Handling
    • Pattern Matching and Parameter
    • Command Line
    • Writing a Plugin
  • Example Projects
  • YouTube Tutorials
  • Ecosystem
  • Packages
    • Authentication
    • CORS
    • Database-Agnostic Relations
    • Configuration
    • Database Adapters
      • MongoDB
      • RethinkDB
      • JSON File-based
      • ORM
    • Front-end
      • Mustache Templates
      • Jael template engine
        • Github
        • Basics
        • Custom Elements
        • Strict Resolution
        • Directive: declare
        • Directive: for-each
        • Directive: extend
        • Directive: if
        • Directive: include
        • Directive: switch
      • compiled_mustache-based engine
      • html_builder-based engine
      • Markdown template engine
      • Using Angel with Angular
    • Hot Reloading
    • Pagination
    • Polling
    • Production Utilities
    • Reverse Proxy
    • Router
    • Serialization
    • Service Seeder
    • Static Files
    • Security
    • Server-sent Events
    • shelf Integration
    • Task Engine
    • User Agents
    • Validation
    • Websockets
Powered by GitBook
On this page
  • @Header()
  • @Query()
  • @Session()
  • @CookieValue()
  • @Parameter()
  1. Guides

Pattern Matching and Parameter

package:angel_framework has nice support for injecting values from HTTP headers, query string, and session/cookie values, as well as pattern-matching for request handlers.

These act as a clean shorthand for commonly-used functionality.

Here is a simple example of each of them in action:

app.get('/cookie', ioc((@CookieValue('token') String jwt) {
    return jwt;
}));

app.get('/header', ioc((@Header('x-foo') String header) {
    return header;
}));

app.get('/query', ioc((@Query('q') String query) {
    return query;
}));

app.get('/session', ioc((@Session('foo') String foo) {
    return foo;
}));

app.get('/match', ioc((@Query('mode', match: 'pos') String mode) {
    return 'YES $mode';
}));

app.get('/match', ioc((@Query('mode', match: 'neg') String mode) {
    return 'NO $mode';
}));

app.get('/match', ioc((@Query('mode') String mode) {
    return 'DEFAULT $mode';
}));

@Header()

A simple parameter annotation to inject the value of a sent HTTP header. Throws a 400 if the header is absent.

@Query()

Searches for the value of a query parameter.

@Session()

Fetches a value from the session.

@CookieValue()

Gets the value of a cookie.

@Parameter()

The base class driving the above matchers.

Supports:

  • defaultValue

  • required

  • custom error message

PreviousError HandlingNextCommand Line

Last updated 6 years ago

https://www.dartdocs.org/documentation/angel_framework/latest/angel_framework/Parameter-class.html