What differentiates a REST web service from a RPC-like one?

前端 未结 5 1545
Happy的楠姐
Happy的楠姐 2021-01-31 04:09

I have a web application that uses AJAX to grab JSON data from the server. It requires that the user first log in with their browser so that a cookie can be set. Only the

5条回答
  •  北恋
    北恋 (楼主)
    2021-01-31 04:38

    Think of it this way -- is it the function that matters, or the information that's being acted on?

    When you're dealing with REST, you're deaing with a state of information -- you look to see what the current information is (GET), or you change that specific document (POST, DELETE), or you create a new document (PUT).

    With RPC, it's about the procedures / function / methods / operations ... whatever you call them in your language. The information is just something that gets operated on or returned from a service ... but it might be one of many. We might be searching, and returning a list of items. Or we might be negotiating something where we need some interaction back and forth. (REST's negotiation for the most part is handled through HTTP, so you have to do things with Accept and Accept-Language header) But it's the operation that's more important.

    Then there's the third type, which is document/literal SOAP ... where it's the message that's important, and you have to guess what the function being called is based on the message. If you're just dealing with CRUD operations, this is probably okay. The advantages over REST in this case is that you can still have a WSDL, so you know in advance what the necessary elements are to send, and what to expect in return.

    They all work ... it's mostly about how you think about the problem, and how easy it is to convert from what you already have to expose it as an API. If you're starting from the ground up, you can likely do whatever you want. I personally like SOAP (either document/lit or RPC) in that I can give a WSDL file that someone can use to bootstrap their client. I've had cases where people were doing serious queries within a couple of hours. (explaining some of the abstract subtleties of the API, such as the difference between sending an empty string vs. a null took some time, but I would've had the same issues w/ REST)

提交回复
热议问题