Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
297 views
in Technique[技术] by (71.8m points)

.net - REST API: GET request with body

I want to implement a REST API and need a body on my GET requests. (Like discussed here: HTTP GET with request body)

Are there http clients which are not able to send a body with a GET request? Fiddler is able to do it, although the message box is red.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

As a general rule, the idea of a GET in REST is that any of your parameters are sent in the URL. As the answer on the question you included indicates, it's doable but misses the point of REST, which is to have a consistent webbish interface. If you want to pass complex data to your endpoint, you probably want to use a POST, which your users will expect to have a body for. I'd highly recommend reconsidering that implementation.

But to your actual question, sure there are clients that can't send a body on a GET. Mostly I'd imagine your clients will be programmatic, say, python's urlib2, and while you can set a body on GET, it is not really the intended use of the module, so you're forcing the programmer to get weird. More importantly, the idea of the REST api is to be client-agnostic, which is why it sounds to me like your API design should be reworked here.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...