darpress 0.0.1

  • Readme
  • Changelog
  • Installing
  • 44

Darpress #

WARNING: This is highly experimental.

Darpress is easy to use, lightweight, annotation free, and no source generation server framework for dart inspired by expressjs.

Usage #

A simple usage example:

import 'package:darpress/darpress.dart';

void main() async{
  final app = Darpress();
  app.post('/todos', (request, response, next) async{
  //TODO: write your logic here.
  await response.send('some response');
  });
  
  app.post('/todos', (request, response, next) async{
  //TODO: write your logic here
  await response.send({'key': 'value'});
  });
    
  final server = await app.listen(); // default port number is 3000
  // you can define the port number if you want.
  // final server = await app.listen(port: 5000);
}

As the routes for your app increases, you may want to use a CustomRouter. It will make your code more organized and easily readable.

import 'package:darpress/darpress.dart';

class UserRouter implements CustomRouter {
  @override
  void route(Router router) {
    router.post('/users', _postUser);
    router.get('/users', _getUsers);
    // OR you can use the builder.
    // router.route('/users').post(_postUser).get(_getUsers);
  }

  Future<void> _getUsers(Request request, Response response, next) async {
    //TODO: write your logic here.
    await response.send('some user data');
  }

  Future<void> _postUser(Request request, Response response, next) async {
    //TODO: write your logic here.
    await response.send('saved user data');
  }
 }

Now you can use the UserRouter in your app.

void main() async{
   final app = Darpress();
   app.route(UserRouter());
   final server = await app.listen();
   // OR you can use the shortcut like this.
   // Darpress().route(UserRouter()).listen();
 }

You can add multiple middlewares on a route.

void main() async {
  final app = Darpress();
  app.get('/colors', (request, response, next) async {
    print('Running the first middleware..');
    await next();
  }, [
    (request, response, next) async {
      print('Running the second middleware..');
      await next();
    },
    (request, response, next) async {
      print('Running the third middleware..');
      await next();
    },
    (request, response, next) async {
      print('Running the last middleware..');
      response.send('Middleware example.');
    }
  ]);
  
  app.listen();
}

Examples #

  • Examples - an example of how to use a custom router and middleares.

Features and bugs #

Please file feature requests and bugs at the issue tracker.

Maintainers #

0.0.1 #

  • Initial version.

Use this package as a library

1. Depend on it

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


dependencies:
  darpress: ^0.0.1

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

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

3. Import it

Now in your Dart code, you can use:


import 'package:darpress/darpress.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
70
Overall:
Weighted score of the above. [more]
44
Learn more about scoring.

We analyzed this package on Jul 9, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.13

Analysis suggestions

Package not compatible with runtime flutter-web on web

Because of the import of dart:io via the import chain package:darpress/darpress.dartpackage:darpress/src/http/http.dartpackage:darpress/src/http/response/response.dartpackage:darpress/src/http/http_object.dartdart:io

Package not compatible with runtime web

Because of the import of dart:io via the import chain package:darpress/darpress.dartpackage:darpress/src/http/http.dartpackage:darpress/src/http/response/response.dartpackage:darpress/src/http/http_object.dartdart:io

Health suggestions

Format lib/darpress.dart.

Run dartfmt to format lib/darpress.dart.

Format lib/src/http/converter/http_converter.dart.

Run dartfmt to format lib/src/http/converter/http_converter.dart.

Format lib/src/http/http.dart.

Run dartfmt to format lib/src/http/http.dart.

Format lib/src/http/response/response_impl.dart.

Run dartfmt to format lib/src/http/response/response_impl.dart.

Format lib/src/route/darpress_router_impl.dart.

Run dartfmt to format lib/src/route/darpress_router_impl.dart.

Maintenance issues and suggestions

Homepage URL doesn't exist. (-20 points)

At the time of the analysis the homepage field https://github.com/Elias8/darpress' was unreachable.

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.

Maintain an example.

None of the files in the package's example/ directory matches known example patterns.

Common filename patterns include main.dart, example.dart, and darpress.dart. Packages with multiple examples should provide example/README.md.

For more information see the pub package layout conventions.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
meta ^1.1.8 1.2.1
path_to_regexp ^0.3.0 0.3.0
Dev dependencies
effective_dart ^1.2.1
mockito ^4.1.1
pedantic ^1.9.0
test ^1.14.7