- Dart:Scalable Application Development
- Davy Mitchell Sergey Akopkokhyants Ivo Balbaert
- 318字
- 2021-07-09 18:56:22
Introducing Dart's server frameworks
The blog server in this project is written directly on top of dart:io
, so you can see what is going on. As you might expect, there are a number of frameworks for Dart to help write server applications, so that basic tasks, such as serving text files, do not have to be implemented from scratch for every application.
These are all available at the pub package library.
Redstone
Redstone is described as "a server-side micro framework for the Dart platform". It uses simple code annotations to expose Dart functions to the Web. The Redstone Hello World
example is very clear, and shows how annotations can hide the complexity from the developer so that they can focus on the application logic:
import 'package:redstone/server.dart' as app; @app.Route("/") helloWorld() => "Hello, World!"; main() { app.setupConsoleLog(); app.start(); }
Note
You can find out more about Redstone at http://redstonedart.org/.
Rikulo
Rikulo modestly describes itself as a lightweight—Dart web server. It has a list of interesting features including request routing, template engine, and the MVC (Model–view–controller) design pattern. Rikulo Stream is the server story and its Hello World
example to serve static content is a single line:
import "package:stream/stream.dart"; void main() { new StreamServer().start(); }
Note
You can find out more about Rikulo at http://rikulo.org/, where several projects are listed.
Shelf
Shelf claims that it makes it easy to create and compose web servers, and parts of web servers. Its pipeline-based model allows middleware (such as a request logger in it's Hello World
example) to be added in:
import 'package:shelf/shelf.dart' as shelf; import 'package:shelf/shelf_io.dart' as io; void main() { var handler = const shelf.Pipeline().addMiddleware(shelf.logRequests()) .addHandler(_echoRequest); io.serve(handler, 'localhost', 8080).then((server) { print('Serving at http://${server.address.host}:${server.port}'); }); } shelf.Response _echoRequest(shelf.Request request) { return new shelf.Response.ok('Request for "${request.url}"'); }
Note
Find out more about Shelf at https://github.com/dart-lang/shelf, and as this URL suggests, this package is from the Dart team.
- INSTANT OpenCV Starter
- SoapUI Cookbook
- MySQL 8從入門到精通(視頻教學版)
- Learning ArcGIS Pro 2
- Bulma必知必會
- Web Application Development with R Using Shiny(Second Edition)
- Python GUI Programming Cookbook
- Quarkus實踐指南:構(gòu)建新一代的Kubernetes原生Java微服務(wù)
- MySQL數(shù)據(jù)庫基礎(chǔ)實例教程(微課版)
- Hands-On GPU:Accelerated Computer Vision with OpenCV and CUDA
- 名師講壇:Spring實戰(zhàn)開發(fā)(Redis+SpringDataJPA+SpringMVC+SpringSecurity)
- Android程序設(shè)計基礎(chǔ)
- UVM實戰(zhàn)
- 零基礎(chǔ)學Kotlin之Android項目開發(fā)實戰(zhàn)
- Beginning C++ Game Programming