evy 0.0.5

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 47

Evy #

Gitter chat

Evy is a Dart 2 Web Framework, with an ExpressJS like API.

Getting Started #

For start using Evy in your project you need to clone this repo and add it to dependencies section in your pubspec.yaml file:

# pubspec.yaml
name: example_app
description: My app

dependencies:
 evy: 
    path: /path/to/evy

Prerequisites #

Example code #

import 'package:evy/evy.dart';

void main() {
  var app = Evy();

  /// This middleware will match all routes.
  app.use(handler: logRequest);

  /// This middleware will be called only for '/greet/:name' routes.
  app.use(path: '/greet/:name', handler: checkName);

  /// This middleware will be called only for '/greet/:name' routes.
  /// It will be executed after checkName middleware.
  app.use(path: '/greet/:name', handler: changeName);

  /// Or just pass the middleware callbacks as a list.
  ///  app.use(path: '/greet/:name', callback: [checkName, changeName]);

  ///Routes can have a callback for process the request.
  app.get(path: '/greet/:name', handler: sayHello);

  ///Path can be a RegExp, this route will match /evy, /evyhi, /whateverevy... .
  app.get(path: RegExp('/.*evy'), handler: sayHello);

  ///Path can be a List of Strings, this will match /users, /user and /client.
  app.get(path: ['/users', '/user', '/client'], handler: sayHello);

  app.listen(
      port: 3000,
      callback: (error) {
        if (error != null) {
          print(error);
        } else {
          print('Server listening on port 3000');
        }
      });
}

void changeName(Request req, Response res, next) {
  if (req.params['name'] == 'Alberto') {
    req.params['name'] = 'Carlos';
  }
  next();
}

void checkName(Request req, Response res, next) {
  if (req.params['name'] != 'Alberto') {
    res.send('Only Alberto is allowed to use this action');
  } else {
    next();
  }
}

void logRequest(Request req, Response res, next) {
  /// Do your logging stuff and then call next()
  print('${req.ip} - - [${DateTime.now()}] "${req.method} ${req.originalUrl}"');
  next();
}

void sayHello(Request req, Response res, next) {
  if (req.params['name'] != null) {
    res.send('Hello ${req.params['name']}');
  } else {
    res.send('Hello');
  }
}

Todo #

  • [X] Implement basic HTTP methods (POST, PUT, etc).
  • [X] Create Request and Response wrappers.
  • [X] Per Route Middlewares.
  • [X] Global Middlewares.
  • [X] Sub-apps app.use(path: '/billing', app: billingApp).
  • [ ] Serve static files (Use a package instead).
  • [ ] Content body parsing (Use a package instead).
  • [ ] Routes group.
  • [ ] Publish package to Dart Packages.
  • [ ] Testing.
  • [ ] Logo design.

0.0.5 #

  • Breaking change. Route callback param has been renamed to handler.
  • Sub-app support via app.use()

0.0.4 #

  • Fix request params being lost in middlewares.
  • Docs

0.0.3 #

  • Per route middleware
  • Response object

0.0.2 #

  • Request object
  • Basic HTTP methods

0.0.1 #

  • Initial Release

example/main.dart

import 'package:evy/evy.dart';

void main() {
  var app = Evy();

  /// This middleware will match all routes.
  app.use(handler: logRequest);

  /// This middleware will be called only for '/greet/:name' routes.
  app.use(path: '/greet/:name', handler: checkName);

  /// This middleware will be called only for '/greet/:name' routes.
  /// It will be executed after checkName middleware.
  app.use(path: '/greet/:name', handler: changeName);

  /// Or just pass the middleware callbacks as a list.
  ///  app.use(path: '/greet/:name', callback: [checkName, changeName]);

  ///Routes can have a callback for process the request.
  app.get(path: '/greet/:name', handler: sayHello);

  ///Path can be a RegExp, this route will match /evy, /evyhi, /whateverevy... .
  app.get(path: RegExp('/.*evy'), handler: sayHello);

  ///Path can be a List of Strings, this will match /users, /user and /client.
  app.get(path: ['/users', '/user', '/client'], handler: sayHello);

  app.listen(
      port: 3000,
      callback: (error) {
        if (error != null) {
          print(error);
        } else {
          print('Server listening on port 3000');
        }
      });
}

void changeName(Request req, Response res, next) {
  if (req.params['name'] == 'Alberto') {
    req.params['name'] = 'Carlos';
  }
  next();
}

void checkName(Request req, Response res, next) {
  if (req.params['name'] != 'Alberto') {
    res.send('Only Alberto is allowed to use this action');
  } else {
    next();
  }
}

void logRequest(Request req, Response res, next) {
  /// Do your logging stuff and then call next()
  print('${req.ip} - - [${DateTime.now()}] "${req.method} ${req.originalUrl}"');
  next();
}

void sayHello(Request req, Response res, next) {
  if (req.params['name'] != null) {
    res.send('Hello ${req.params['name']}');
  } else {
    res.send('Hello');
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  evy: ^0.0.5

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:evy/evy.dart';
  
Version Uploaded Documentation Archive
0.0.5 Aug 28, 2018 Go to the documentation of evy 0.0.5 Download evy 0.0.5 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
97
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
88
Overall:
Weighted score of the above. [more]
47
Learn more about scoring.

We analyzed this package on Apr 4, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.2.0
  • pana: 0.12.14

Platforms

Detected platforms: Flutter, other

Primary library: package:evy/evy.dart with components: io.

Health suggestions

Fix lib/src/server.dart. (-1.49 points)

Analysis of lib/src/server.dart reported 3 hints:

line 31 col 19: Use = to separate a named parameter from its default value.

line 31 col 42: Use = to separate a named parameter from its default value.

line 44 col 7: Use rethrow to rethrow a caught exception.

Fix lib/src/router/route.dart. (-1 points)

Analysis of lib/src/router/route.dart reported 2 hints:

line 8 col 17: The value of the field '_path' isn't used.

line 32 col 9: Use isEmpty instead of length

Fix lib/src/router/middleware.dart. (-0.50 points)

Analysis of lib/src/router/middleware.dart reported 1 hint:

line 74 col 70: Use = to separate a named parameter from its default value.

Fix lib/src/router/router.dart. (-0.50 points)

Analysis of lib/src/router/router.dart reported 1 hint:

line 27 col 9: Use isEmpty instead of length

Maintenance suggestions

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

The package description is too short. (-2 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.67.0 <3.0.0