[英]http.get vs http.request in Angular
I noticed people use 2 ways of retrieving data from remote source: http.get()
and http.request()
. 我注意到人们使用两种从远程源检索数据的方式:
http.get()
和http.request()
。
What is the difference between http.get()
and http.request()
method in Angular? http.get()
和http.request()
方法有什么区别?
http.get()
is just a shorthand to using http.request()
with the method
field of the Request
argument set as RequestMethod.Get
. http.get()
仅仅是一个速记使用http.request()
与method
所述的字段Request
设定为参数RequestMethod.Get
。
The same goes for the http
methods named with a HTTP verb : 以HTTP动词命名的
http
方法也是如此:
http.put()
http.post()
http.delete()
http.head()
http.patch()
http.options()
(with, depending on the method, some convenient other arguments as shortcut for the relevant RequestOption
, such as body
for http.post()
) (根据方法,使用一些方便的其他参数作为相关
RequestOption
快捷方式,例如http.post()
body
)
So the actual only difference is just readability , but that's IMHO important enough to prefer these specific methods over directly using http.request()
因此,实际的唯一区别只是可读性 ,但是IMHO非常重要,它比直接使用
http.request()
更喜欢使用这些特定方法
For information, here is the relevant documentation link : https://angular.io/api/http/Http#members , a good place to start for any basic question on the meaning and syntax of the common Angular objects and methods. 有关信息,请参见以下相关文档链接: https : //angular.io/api/http/Http#members ,是开始就常见Angular对象和方法的含义和语法提出任何基本问题的好地方。
Also, don't forget that Angular is Open Source, you can just search for any code of the various packages, and have a look at it! 另外,别忘了Angular是开源的,您可以搜索各种包中的任何代码,然后看看它!
Here is the source for http : https://github.com/angular/angular/blob/master/packages/http/src/http.ts . 这是http的来源: https : //github.com/angular/angular/blob/master/packages/http/src/http.ts 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.