Rails respond_with — why does POST return a URL instead of the data?

前端 未结 3 606
甜味超标
甜味超标 2021-02-12 14:57

This is a question \"why does it work this way\", not \"how do I make this work\".

My app is calling a third party REST API that returns JSON, and returning the result a

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-12 15:25

    To answer this question: "why should an API return anything other than data (and the HTTP status?). I am not saying it's wrong, just trying to understand the rationale."

    I can think of no good rationale. More importantly, I can't see any way that an API could return anything except a data structure! (This question doesn't make sense to me!)

    By definition, an API call must return a data structure. (It might be as simple as a string. It might be JSON. It might be XML.) It can use content negotiation to decide on the format. It may or may not be a strict schema, but at the very least a client library must be able to parse it. In any case, the API documentation should make this abundantly clear and stick to it. How else can client libraries expect to interoperate?

    I think I'm missing the point here, this seems too obvious. (I suspect you are having another problem in your code above.)

提交回复
热议问题