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

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.

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