【问题标题】:Mock API Responses on AndroidAndroid 上的模拟 API 响应
【发布时间】:2019-12-04 17:43:39
【问题描述】:

我正在创建一个需要 api 调用的 android 应用程序,该 api 仍在开发中,但我想创建一个虚拟改造 api 请求,它将返回一个实际的 json 值作为响应,以便我可以加快应用程序的开发。但是现在不知道怎么弄了,网上找了答案,好像没看懂。

【问题讨论】:

    标签: java android api retrofit2


    【解决方案1】:

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

    使用 Retrofit/Okhttp mock,您可以将 json 文件放在 assets 文件夹中,并配置 retrofit mock/okhttp mock 以在命中特定端点时将 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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-05-09
      • 1970-01-01
      • 2018-11-28
      • 2020-02-04
      • 2023-02-07
      • 2021-10-15
      • 2016-08-16
      • 1970-01-01
      相关资源
      最近更新 更多