开发者

Invoking REST api using POST method invokes GET method

开发者 https://www.devze.com 2023-04-06 20:12 出处:网络
I am developing a firefox plugin which invokes a rest api using post method. The rest api will persist the data if it is invoked using POST. If it is invoked using GET method开发者_如何学Go, it will r

I am developing a firefox plugin which invokes a rest api using post method. The rest api will persist the data if it is invoked using POST. If it is invoked using GET method开发者_如何学Go, it will retrieve the data persisted previously.

But in some cases, the api returns the persisted data even though it is invoked using the POST data.

I am under confusion whether the way I send the data is wrong or whether there is something wrong with api. But most of the requests gets served correctly. So, I don't think that there is something wrong with plugin. Te back end is on ROR.

Any help will be great!

Thanks.


It's not uncommon for RESTful services to return a copy of the (updated) data in response to a POST.

All you really care about is that it's updating the remote data when you POST. Whether or not it returns a copy of that data is something you may be able to safely ignore.


If it's intermittent, one possibility is that there is an HTTP cache in between your server and client which is poorly implemented, and doesn't differentiate properly between the GET and POST methods. Perhaps it is attempting to return a cached copy as if you had made a GET request even though you sent a POST request.

If instead "in some cases" means "for some URL's", then it's possible that you are POST'ing to a URL like "/foo" (no trailing slash) and the service returns 301 or 302, redirecting the client to "/foo/" (with a trailing slash). Most user-agents will change the POST to a GET for 302, and some will for 301. If you have control over the server, you should use 303 or 307 instead. See https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-p2-semantics-16#section-8.3.3

0

精彩评论

暂无评论...
验证码 换一张
取 消