start 0.2.7

  • README.md
  • CHANGELOG.md
  • Installing
  • Versions
  • 34

Start

Sinatra inspired web framework.

It has simple API to serve static files, handle dynamic requests, websockets and create JSON responses.

import 'package:start/start.dart';

void main() {
  start(port: 3000).then((Server app) {

    app.static('web');

    app.get('/hello/:name.:lastname?').listen((request) {
      request.response
        .header('Content-Type', 'text/html; charset=UTF-8')
        .send('Hello, ${request.param('name')} ${request.param('lastname')}');
    });

    app.ws('/socket').listen((socket) {
      socket.on('ping').listen((data) => socket.send('pong'));
      socket.on('pong').listen((data) => socket.close(1000, 'requested'));
    });

  });
}

API

start()

You start the server with start() function. It has 3 named arguments and returns Server future

start({String host: '127.0.0.1', int port: 80})

Server

listen(host, port) // start the server (it's performed by the start function)
stop() // stops the server
get|post|put|delete(String route) // adds a handler, returns a Stream<Request>
ws(String route) // adds WebSocket handler, returns a Stream
static(String path, {bool jail, bool listing, bool links}) // serves static files from `path`, follows symlinks outside the root if jail is false

Routes

Route is a string with placeholders like :firstname its value is available through the Request param() method. Placeholders should start with colon :, if placeholder ends with a question mark ? it's optional. "/hello/:firstname.:lastname?" will match "/hello/john" and "/hello/john.doe"

Request

header(String name) // get header
accepts(String type) // check accept header
input // raw HttpRequest stream
path // requested URI path
uri // requested URI
cookies // provided cookies
param(String name) // get query param by name
payload(Encoding enc) // get a promise with a Map of request body params

Response

header(String name, [value]) // get or set header
get(String name) // get header
set(String name) // set header
type(contentType) // set Content-Type
cache(String cacheType) // set Cache-Control
status(code) // sets response status code
cookie(name, val) // sets cookie
add(string) // add a string to response
close() // closes response
send(string) // sends string and closes response
json(Map data) // stringifies map and sends it
jsonp(String name, Map data) // stringifies map and sends it in callback as `name(data)`
render(viewName, [Map params]) // renders server view

Socket

send(message) // sends message
on(message, action) // adds handler to message
close(status, reason) // closes socket

License

(The MIT License)

Copyright (c) 2012 Yehor Lvivski lvivski@gmail.com

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Changelog

0.0.8

Breaking changes. Removed hart dependency, start now uses proper Cookie library, serves index.html by default

0.0.7

This update is dependent on a breaking change in the latest version of the Dart stdlib. Please make sure you update to the latest version of Dart before installing.

  • Change HttpRequest.queryParameters to HttpRequest.uri.queryParameters.

1. Depend on it

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


dependencies:
  start: "^0.2.7"

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:start/start.dart';
        
Version Uploaded Documentation Archive
0.2.7 Aug 16, 2014 Go to the documentation of start 0.2.7 Download start 0.2.7 archive
0.2.5 Aug 1, 2014 Go to the documentation of start 0.2.5 Download start 0.2.5 archive
0.2.4 Apr 29, 2014 Go to the documentation of start 0.2.4 Download start 0.2.4 archive
0.2.3 Feb 25, 2014 Go to the documentation of start 0.2.3 Download start 0.2.3 archive
0.2.2 Feb 25, 2014 Go to the documentation of start 0.2.2 Download start 0.2.2 archive
0.2.1 Feb 24, 2014 Go to the documentation of start 0.2.1 Download start 0.2.1 archive
0.2.0 Jan 21, 2014 Go to the documentation of start 0.2.0 Download start 0.2.0 archive
0.1.2 Dec 23, 2013 Go to the documentation of start 0.1.2 Download start 0.1.2 archive
0.1.1 Nov 16, 2013 Go to the documentation of start 0.1.1 Download start 0.1.1 archive
0.1.0 Nov 14, 2013 Go to the documentation of start 0.1.0 Download start 0.1.0 archive

All 27 versions...

Analysis

This feature is new.
We welcome feedback.

We analyzed this package, and provided a score, details, and suggestions below.

  • tool failures on Dec 6, 2017
  • Dart: 2.0.0-dev.8.0
  • pana: 0.7.3+1

Scores

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

Platforms

Detected platforms: server

primary library - package:start/start.dart

Suggestions

  • Fix lib/src/request.dart.

    Strong-mode analysis of lib/src/request.dart failed with the following error:

    line: 13 col: 40
    The argument type '(String) → int' can't be assigned to the parameter type '(String) → bool'.

Dependencies

Package Constraint Resolved Available
Direct dependencies
http_server any 0.9.6
logging any 0.11.3+1
Transitive dependencies
mime 0.9.4
path 1.5.1
Dev dependencies
browser any
unittest >=0.2.7