Book Image

Learning Dart

Book Image

Learning Dart

Overview of this book

Table of Contents (19 chapters)
Learning Dart
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

A Dart web server


The Dart VM can also run as a server application on the command line or as a background job. When creating the application, choose the command-line application template. Most of Dart's server functionality lives in the dart:io library, which cannot be used in writing browser Dart apps; in the same way, dart:html cannot be used on the server. The class HttpServer is used to write Dart servers; a server listens on a particular host and port for incoming requests and provides event handlers (so-called request handlers) that are triggered when a request with incoming data from a client is received. The latter is described by the class HttpRequest, which is an asynchronous API provided by the browser (formerly known as Ajax) and has properties, such as method, path, query parameters, and InputStream with the data. The server responds by writing to the OutputStream of an HttpResponse object. The following is the code of the project webserver, where you can easily see all parts...