1

I know this is probably a long-shot, but is it possible to use Siesta with a completely non-RESTful API? The API I have to work with (and is not in my control so sadly cannot change) requires every request to be a POST request regardless of whether it is purely retrieving data or not.

I've had a read through the question/answer here which gives me a glimmer of hope, however the big difference between that question and mine is the endpoints of each request. For the API I'm using, they're all the same :(

Every single request must POST to /api/api_post.php, and everything else is specified as a parameter supplied in the request.

Obviously I can roll my own request wrapper to handle this, but I'd love to be able to use some of the functionality provided by Siesta and not have to worry about all the annoyances of dealing with networking. Is there any way of doing this at all, or am I out of luck?

4

1 回答 1

1

您可以让您的应用程序使用虚构的 REST API,然后将其转换为 Siesta 眼皮底下的非 RESTful 请求。(例如,GET /foo/3可能转换为POST /api/api_post.phpwith item=foo&id=3。)这有点麻烦,但它确实为您带来了 Siesta 的好处,即使对于非 REST API 也是如此。

有两种方法可以实现这一点:

  1. 用于mutateRequests(…)重写请求。这使您可以在发送之前任意更改URLRequest它。
  2. 自己写NetworkingProvider。这有点麻烦,但对重写提供了更多的批发控制。例如,如果您还需要重写响应,或者您必须将一个虚拟请求转换为多个真实请求,则这种方法可能更合适。

更多的讨论在这里

于 2017-08-23T15:30:44.950 回答