webart 0.3.0

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

web.dart

A lightweight web framework for Dart.

WARNING: Although supported dart 2, please do not use that

Dart 2 has bad performance because of Strong Mode, seems like it just a another name of Dart 1's Checked Mode... Dart 2 is slower than Dart 1.24.3 ~60%. Use the version ends of -dart1c to use this library with Dart 1.

Features

  • Web server (Thanks to shelf)
  • Plugin
  • Router
  • Context

Usage

This example show the basic usage of web.dart

  webart:
    git: https://gitlab.com/thislight/web.dart.git

Or

  webart: any

Code:

import "package:webart/web.dart";

main(){
    // Create app
    Application app = new Application(
        new Config(<String, dynamic>{
            "debug": true,
            "route":{
                "": helloWorldHandler,
            }
        })
    );

    // Start app
    app.start("127.0.0.1", 8088);
}

// Define handler
Future helloWorldHandler(Request request) async{
    request.res.ok("Hello World");
}

Document

Currently, API documents aren't finished. But you can get an overview of this library.

Documents will be built when new changes are pushed and on 4:00 (UTC+8) of everyday.

The document of branch master

The document of branch develop

LICENSE

Copyright 2017 thisLight

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

CHANGELOG

0.3.0

  • Support Dart 2 Strong Mode

0.2.6

  • Add class-based RequestHandler by RequestHandlerBase, just extends it and add RequestHandlerBase.handler(Instance) to routes
  • now support sceurityContext and backlog config item
  • Add new documents
  • Bugs fix

0.2.5

  • HOTFIX: Remove Dart 2 support

0.2.4

  • HOTFIX: Remove 3rd package for Dart 2 support

0.2.3

  • Fix response of method OPTIONS
  • add configure item allow_global_cors to Allow Global CORS
  • Remove custom sever header
  • Add function allowCORSRequest allow respond server headers that including some Access-Control-Allow-*
  • Add BroadcastResults to support that return value from a command
  • Add CommandLock to wait command done
  • Add optional param includingLock to Command for adding a CommandLock to Command.args['lock']
  • Redo BroadcastResults impl in Command, from Command.broadcastResult move to Command.args['_broadcastResult']
  • Remove command Request.beforeHandling
  • Now command Application.beforeRequestHandling will be runned before Routing and Handling

0.2.2

  • Fix Dart SDK version

0.2.1

  • Allow Command has a Completer to return a value
  • ChannelSession.send will return the future of Command's Completer if has
  • Fix example
  • Add Application.ready to touch some events must touch
  • some bug fixes

0.2.0

  • Release 0.2.0
    • Fix performance problem while running handler, move waitForResponse to trash
    • Add EventBus for plugin
    • Redesign route system, allow using third party router
    • Redesign layer system, get Go away and make it powerful
    • A bit tests for EventBus
    • Fix error that handler not handled
    • Fix error that handler will be called twice
    • return not found when not handler found
    • Remove LoggingLayer
    • Request.on changes to async
    • New MessageChannel, ChannelSession, ChannelSeesionMessage and Command
    • Return HTTP error 404 when handler not found
    • Router will be fast if uri path is static (for example '/about')
    • Builtin Router now work as a Plugin by RoutingPlugin, it also use third party router if given
    • A dirty fix for uri template "" match all uri
    • Package structure changed, all of Layer moved to single 'package:webart/layer.dart'
    • Small change for example.
    • Code opz.,remove unused imports and functions
    • Mark EvevntBus as deprecated, it will be removed when 0.2.0 released.
    • Update logging system, supported debug mode.Just add 'debug': true to config.
    • Mark Layer system as deprecated
    • Remove deprecated entries
    • Some fixes update
    • Fix some error while run on strong mode
    • Add some tests
    • Edit README

0.2.0-beta.5

  • Fix some error while run on strong mode
  • Add some tests
  • Edit README

0.2.0-beta.4

  • Some fixes update

0.2.0-beta.3

  • Remove deprecated entries

0.2.0-beta.2

  • Mark Layer system as deprecated

0.2.0-beta.1

  • Update logging system, supported debug mode.Just add 'debug': true to config.

0.2.0-beta.0

  • New MessageChannel, ChannelSession, ChannelSeesionMessage and Command
  • Return HTTP error 404 when handler not found
  • Router will be fast if uri path is static (for example '/about')
  • Builtin Router now work as a Plugin by RoutingPlugin, it also use third party router if given
  • A dirty fix for uri template "" match all uri
  • Package structure changed, all of Layer moved to single 'package:webart/layer.dart'
  • Small change for example.
  • Code opz.,remove unused imports and functions
  • Mark EvevntBus as deprecated, it will be removed when 0.2.0 released.

0.2.0-alpha.6

  • Remove LoggingLayer
  • Request.on changes to async

0.2.0-alpha.5

  • return not found when not handler found

0.2.0-alpha.4

  • Fix error that handler will be called twice

0.2.0-alpha.3

  • Fix error that handler not handled

0.2.0-alpha.2

  • Add EventBus for plugin
  • Redesign route system, allow using third party router
  • Redesign layer system, get Go away and make it powerful
  • A bit tests for EventBus

0.2.0-alpha.1

  • Fix performance problem while running handler, move waitForResponse to trash

0.1.0

  • First version

example/example.dart

import 'dart:async' show Future;
import "package:webart/web.dart";


main(){
    var app = new Application(
        new Config(<String, dynamic>{
            'debug': false,
            "routes":<String,RequestHandler>{
                "hello/{name}": helloPage,
                "query{?q}": queryPage,
                "json{?key,lang}": getJsonPage,
                "class":new MyRequestHandler(),
                "class2": (new MyRequestHandler()).handler,
                "": homePage,
            }
        })
    );
    app.start("127.0.0.1", 8088);
}

Future homePage(Request request) async{
    request.res.ok("This is home");
}

Future helloPage(Request request) async{
    String name = request.context("urlparam")["name"];
    request.res.ok("Hello, $name");
}

Future queryPage(Request request) async{
    if (request.only(["get"])){
        String qstr = request.context("urlparam")["q"];
        request.res.ok("You are finding $qstr");
    }
}

Future getJsonPage(Request request) async{
    Map data = {
        "data1": {
            "zh": "你好",
            "en": "Hello",
        },
        "data2": {
            "zh": "再见",
            "en": "Godbye",
        }
    };
    Map<String, String> param = request.context("urlparam");
    await request.on("get",(_) async => request.res.ok({ "result": data[param["key"]][param["lang"]]}));
}

class MyRequestHandler extends RequestHandlerBase{
    String data = "OK";

    Future get(Request request) async{
        logger.info("GET FROM MYREQUESTHANDLER");
        request.res.ok(data);
    }

    Future post(Request request) async{
        data = await request.body;
        logger.info("POST TO MYREQUESTHANDLER");
        request.res.ok(data);
    }
}

Use this package as a library

1. Depend on it

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


dependencies:
  webart: ^0.3.0

2. Install it

You can install packages from the command line:

with pub:


$ pub get

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

3. Import it

Now in your Dart code, you can use:


import 'package:webart/webart.dart';
  
Version Uploaded Documentation Archive
0.3.0 Aug 20, 2018 Go to the documentation of webart 0.3.0 Download webart 0.3.0 archive
0.2.6 Aug 19, 2018 Go to the documentation of webart 0.2.6 Download webart 0.2.6 archive
0.2.0 Jul 12, 2018 Go to the documentation of webart 0.2.0 Download webart 0.2.0 archive
0.3.0-dart1c Aug 20, 2018 Go to the documentation of webart 0.3.0-dart1c Download webart 0.3.0-dart1c archive
0.2.0-beta.5 Jul 11, 2018 Go to the documentation of webart 0.2.0-beta.5 Download webart 0.2.0-beta.5 archive
0.2.0-beta.4 Jul 11, 2018 Go to the documentation of webart 0.2.0-beta.4 Download webart 0.2.0-beta.4 archive
0.2.0-beta.3 Jul 11, 2018 Go to the documentation of webart 0.2.0-beta.3 Download webart 0.2.0-beta.3 archive
0.2.0-beta.2 Jul 11, 2018 Go to the documentation of webart 0.2.0-beta.2 Download webart 0.2.0-beta.2 archive
0.2.0-beta.0 Jul 7, 2018 Go to the documentation of webart 0.2.0-beta.0 Download webart 0.2.0-beta.0 archive
0.2.0-alpha.6 Feb 18, 2018 Go to the documentation of webart 0.2.0-alpha.6 Download webart 0.2.0-alpha.6 archive

All 14 versions...

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

We analyzed this package on Dec 5, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.1.0
  • pana: 0.12.7

Platforms

Detected platforms: other

Primary library: package:webart/webart.dart with components: io, isolate, mirrors.

Health issues and suggestions

Document public APIs (-9.07 points)

117 out of 129 API elements (library, class, field or method) have no adequate dartdoc content. Good documentation improves code readability and discoverability through search.

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

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

line 10 col 8: Unused import: './cmd.dart'.

Format lib/src/class_handler.dart.

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

Format lib/src/cmd.dart.

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

Fix additional 6 files with analysis or formatting issues.

Additional issues in the following files:

  • lib/src/context.dart (Run dartfmt to format lib/src/context.dart.)
  • lib/src/dart2/json.dart (Run dartfmt to format lib/src/dart2/json.dart.)
  • lib/src/dart2/platform.dart (Run dartfmt to format lib/src/dart2/platform.dart.)
  • lib/src/logging.dart (Run dartfmt to format lib/src/logging.dart.)
  • lib/src/plugin.dart (Run dartfmt to format lib/src/plugin.dart.)
  • lib/src/web.dart (Run dartfmt to format lib/src/web.dart.)

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.8.0 <3.0.0
logging ^0.11.3 0.11.3+2
shelf ^0.7.3 0.7.3+3
uri_template_r ^0.6.0 0.6.2
Transitive dependencies
async 2.0.8
charcode 1.1.2
collection 1.14.11
http_parser 3.1.3
matcher 0.12.4
meta 1.1.6
path 1.6.2
quiver 2.0.1
source_span 1.4.1
stack_trace 1.9.3
stream_channel 1.6.8
string_scanner 1.0.4
typed_data 1.1.6
utf 0.9.0+5
Dev dependencies
http ^0.11.3
test ^1.3.0