- Dart:Scalable Application Development
- Davy Mitchell Sergey Akopkokhyants Ivo Balbaert
- 93字
- 2021-07-09 18:56:32
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.
推薦閱讀
- Mastering Visual Studio 2017
- Progressive Web Apps with React
- RTC程序設計:實時音視頻權威指南
- Instant 960 Grid System
- Visual Basic程序設計與應用實踐教程
- 軟件項目管理實用教程
- Visual FoxPro程序設計
- Advanced Oracle PL/SQL Developer's Guide(Second Edition)
- ExtJS Web應用程序開發指南第2版
- Xcode 6 Essentials
- Laravel Application Development Blueprints
- Managing Microsoft Hybrid Clouds
- R語言數據挖掘:實用項目解析
- SQL Server實例教程(2008版)
- Getting Started with JUCE