O'Reilly logo

Dart: Scalable Application Development by Ivo Balbaert, Sergey Akopkokhyants, Davy Mitchell

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Receiving data on the web server

In the previous recipe, we made a client app that sends its data to a web server in JSON format. In this recipe, we will make the web server that receives this data step by step, possibly process it, and then send it back to the client. You can find the code in the script server\webserver.dart in the project post_form.

How to do it...

Perform the following steps to make this work:

  1. The following is the code that starts the web server:
    import 'dart:io';
    
    const HOST = '127.0.0.1';
    const PORT = 4040;
    
    void main() {
      HttpServer.bind(HOST, PORT).then(acceptRequests, onError: handleError);
    }
  2. The acceptRequests function describes how the web server handles incoming requests based on their method as follows:
    void acceptRequests(server) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required