Skip to content
This repository has been archived by the owner on Mar 17, 2023. It is now read-only.

unger1984/dia_body

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DEPRECATED! Move to MONOREPO https://github.com/unger1984/dia

Pub Package

The request body parser middleware for Dia. Parse query, x-www-form-urlencoded, json and form-data params and uploaded files form HttpRequest.

Install:

Add to pubspec.yaml in dependencies section this:

    dia_body: ^0.1.2

Then run pub get

Usage:

A simple usage example:

class ContextWithBody extends Context with ParsedBody {
  ContextWithBody(HttpRequest request) : super(request);
}

void main() {
  final app = App((req) => ContextWithBody(req));

  app.use(body());

  app.use((ctx, next) async {
    ctx.body = ''' 
    query=${ctx.query}
    parsed=${ctx.parsed}
    files=${ctx.files}
    ''';
  });

  /// Start server listen on localhsot:8080
  app
      .listen('localhost', 8080)
      .then((info) => print('Server started on http://localhost:8080'));
}

Optional named params:

  • uploadDirectory - directory for upload files. Default: Directory.systemTemp

Use with:

  • dia - A simple dart http server in Koa2 style.
  • dia_router - Middleware like as koa_router.
  • dia_cors - CORS middleware.
  • dia_static - Package to serving static files.

Migration from 0.0.*

change

final app = App<ContextWithBody>();

to

final app = App((req) => ContextWithBody(req));

Features and bugs:

I will be glad for any help and feedback! Please file feature requests and bugs at the issue tracker.

About

The request body parser middleware for Dia http server

Resources

License

Stars

Watchers

Forks

Languages