java - Android 上的模拟 API 响应

标签 java android api retrofit2

我正在创建一个需要 api 调用的 android 应用程序,该 api 仍在开发中,但我想创建一个虚拟改造 api 请求,该请求将返回实际的 json 值作为响应,以便我可以加快应用程序开发速度。但现在我不知道该怎么办,我在网上搜索了答案,但我似乎什么也不明白。

最佳答案

有几种方法可以做到这一点。

使用 Retrofit/Okhttp 模拟,您可以将 json 文件放置在 Assets 文件夹中,并配置 Retrofit mock/okhttp 模拟,以便在命中特定端点时将 json 文件作为响应。

  1. Retrofit Mock [在您的应用程序中运行] https://github.com/square/retrofit/tree/master/retrofit-mock

  2. OKHttp Mock [在您的应用程序中运行] https://github.com/square/okhttp/tree/master/mockwebserver

  3. Json-server [在您的 PC/Mac 上运行] https://github.com/typicode/json-server

关于java - Android 上的模拟 API 响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59181950/

相关文章:

android反序列化对象?

python - 使用 GRASS GIS API 的 python 脚本错误

java - boolean 条件验证

java - 如何将 AggregateIterable<Document> 值保存到 mongodB 中的 map ?

java - 如何打印出字符串的所有子串?

python - 使用 extended for cursor 在 Freebase Python API 中不起作用?

node.js - 如何在 Nodejs 中使用 Twilio API 将 "say"消息添加到 session 开始

java - 包含 JPanel 的 JScrollPane 不会滚动

android - 安全购买溢价 IAP

android - 将电脑变成安卓手机的底座