一个正常的API的输出和一个REST API之间差 [英] Difference between an Output of a normal API and a REST API

查看:169
本文介绍了一个正常的API的输出和一个REST API之间差的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是什么REST API和正常之间的API(它打印JSON响应)有什么区别?

What is the difference between a REST API and a normal API (which prints a JSON response)?

推荐答案

有什么区别的。 REST描述了一种具有HTTP服务器,而不是什么服务器应在响应中返回交互的一种方式。大多数Web应用程序与POST在服务器端进行交互或GET与履行提交表单POST为或GET查询字符串的请求所需的任何其他信息的请求。所以,如果你想从服务器上删除的东西,他们通常做的帖子,其中包含指定要删除它一个指令沿着资源数据的形式。

There is no difference at all. REST describes a way of interacting with a HTTP server, not what the server should return in response. Most web apps interact with the server side by POST or GET requests with any additional information needed to fulfil the request in a form submission for POST or the query string for GET. So if you want to delete something from the server they typically do POST with a form that contains data that specifies a resource along with an instruction to delete it.

然而,HTTP实现比GET或POST的其它方法(也称为动词)​​。它还实现,除其他外,HEAD(回报你会做一个GET相同的头文件,但没有响应体),PUT(取请求主体和存储其内容的任何URL的PUT请求作出),和DELETE(删除任何资源在指定的URL存在)。一个REST接口简单使用这些额外的动词来convay请求到服务器的意义。

However, HTTP implements methods (also known as verbs) other than GET or POST. It also implements, amongst others, HEAD (return the same headers you would have done for a GET, but with no response body), PUT (Take the request body and store its content at whatever URL the PUT request was made to), and DELETE (Delete whatever resource exists at the specified URL). A REST interface simply makes use of these additional verbs to convay the meaning of the request to the server.

浏览器通常只支持GET和POST为正常(非XHR)请求,但工具,如卷曲可以发出全套HTTP动词。您还可以使用额外的动词与基于XHR技术,如AJAX。

Browsers typically only support GET and POST for "normal" (non-XHR) requests, but tools like Curl can issue the full set of HTTP verbs. You can also use additional verbs with XHR-based techniques such as AJAX.

您还必须提供传统的非REST API的浏览器使用,除非你让JavaScript和XHR支持使用你的应用程序的要求。

You will still have to provide a traditional non-REST API for browsers to use, unless you're making javascript and XHR support a requirement for using your app.

这篇关于一个正常的API的输出和一个REST API之间差的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆