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

Passing parameters to the API


One method of providing input to a REST API is via the calling URL, and this will be used to get a specified number of entries from the database using the following URL:

http://127.0.0.1:8080/api/quake/v1/recent/100

The implementation involves extending the pattern of the path with a curly bracket syntax (these correspond to the String parameters in the function):

  @ApiMethod(path: 'recent/{count}')
  Future<List<String>> recent(String count) async {
    DaoQuakeAPI quakeAPI = new DaoQuakeAPI();
    return await quakeAPI.fetchRecent(int.parse(count));
  }

The int.parse method is used to convert the count string into a database query parameter.