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
  1. Guides

Writing a Plugin

PreviousCommand LineNextPackages

Last updated 6 years ago

Writing a is easy. You can provide plug-ins as either functions, or classes:

AngelConfigurer awesomeify({String message = 'This request was intercepted by an awesome plug-in.'}) {
  return (Angel app) async {
    app.fallback((req, res) async => res.write(message));
  };
}

class MyAwesomePlugin {
  @override
  Future<void> configureServer(Angel app) async {
    app.responseFinalizers.add((req, res) async {
      res.headers['x-be-awesome'] = 'All the time :)';
    });
  }
}

await app.configure(MyAwesomePlugin().configureServer);

Guidelines

  • Plugins should only do one thing, or serve one purpose.

  • Functions are preferred to classes.

  • Always need to be well-documented and thoroughly tested.

  • Make sure no other plugin already serves the purpose.

  • Use the provided Angel API's whenever possible. This will help your plugin resist breaking change in the future.

  • Try to get it added to the angel-dart organization (ask in the chat).

  • Plugins should generally be small, as they usually serve just one purpose.

  • Plugins are allowed to modify app configuration.

  • Stay away from req.rawRequest and res.rawResponse if possible. This can restrict people from

    using your plugin on multiple platforms.

  • Avoid checking app.isProduction; leave that to user instead.

  • Always use req.parseBody() before accessing the request body.

This can greatly aid readability, as there is simply less text to read in the most common cases.

main() {
  var app = new Angel();

  // Calling gzip()
  app.responseFinalizers.add(gzip());

  // Easier than:
  app.responseFinalizers.add(compress('lzma', lzma));
}

Finally, your plugin should expose common options in a simple way. For example, the (deprecated) plugin has a shortcut function, gzip, to set up GZIP compression, whereas for any other codec, you would manually have to specify additional options.

compress
plug-in
Guidelines