Book Image

Dart By Example

By : David Mitchell
Book Image

Dart By Example

By: David Mitchell

Overview of this book

Table of Contents (17 chapters)
Dart By Example
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Posting on the API


In the georestwebservice project in this chapter, the source code is an updated version of the API with the new recordFeature method in the daoapi.dart file, which is as follows:

Future<List<String>> recordFeature(String json) async {
  var dbConn;
  DateTime time = new DateTime.now();
  String featureID = time.millisecondsSinceEpoch.toString();
  List<String> result = new List<String>();

  try {
    dbConn = await connect(uri);

    await dbConn.execute(
        'insert into dm_quakefeatures (qufeat_id, geojson) values (@qufeat_id, @geojson)',
        {'qufeat_id': featureID, 'geojson': json});
  } catch (exception, stacktrace) {
    print(exception);
    print(stacktrace);
  } finally {
    dbConn.close();
  }
  result.add(featureID);
  return result;
}

This method will create a featureID string for the incoming feature's details, which is then inserted in to the dm_quakefeatures table together with the supplied data from the client. The generated...