我想用我的自定义 Grape API(Ruby on Rails)在 Android 上实现一个休息客户端,并且想知道从哪里开始(换句话说,如果有关于在 Android 操作系统上实现它的良好实践......或者任何好的和最近的例子关于它。)
谢谢你。我很快就会发布我的解决方案。
所以基本上,我的rest API(在葡萄中)中有一个看起来像这样的方法。
“http://localhost:3000/api/signin/”
基本上,如果我执行此命令行,我可以访问/验证:
curl -H "Accept: application/vnd.lzgo-v1+json" -d email=myuser -d password=mypassword http://localhost:3000/api/signin/
现在,我正在尝试构建一种通用的方式来访问我的 API,显然是在 android 上。到目前为止,我一直在使用带有RestService的这个家伙。
Intent intent = new Intent(activity, com.android.lzgo.service.RESTService.class);
intent.setData(Uri.parse("http://localhost:3000/api/signin/"));
Bundle params = new Bundle();
params.putString("email", "myuser");
params.putString("password", "mypassword");
intent.putExtra(RESTService.EXTRA_HTTP_VERB, RESTService.POST);
intent.putExtra(RESTService.EXTRA_PARAMS, params);
intent.putExtra(RESTService.EXTRA_RESULT_RECEIVER, getResultReceiver());
然后,当我的案例是 POST 时,我对 RestService 实现有点困惑。
UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(paramsToList(params));
postRequest.setHeader("Accept", "application/vnd.lzgo.v1+json");
postRequest.setEntity(formEntity);
如果您在顶部查看我的 URL,它似乎更像是参数,所以我可能会使用 postRequest.setParams()...