- 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.
推薦閱讀
- Instant Node Package Manager
- 小程序實戰視頻課:微信小程序開發全案精講
- 技術領導力:程序員如何才能帶團隊
- Learning Bayesian Models with R
- Nginx Essentials
- CouchDB and PHP Web Development Beginner’s Guide
- Node.js Design Patterns
- Visual Basic程序設計
- 持續集成與持續交付實戰:用Jenkins、Travis CI和CircleCI構建和發布大規模高質量軟件
- 一步一步跟我學Scratch3.0案例
- UML軟件建模
- Java EE架構設計與開發實踐
- SQL Server on Linux
- SAS編程演義
- 自己動手構建編程語言:如何設計編譯器、解釋器和DSL