admin管理员组文章数量:1308578
I was reading a tutorial on the web on ES6 and I am pretty sure that I read that there is a native way to call REST Web services by using ES6.
Now I am googling on that topic and I just cannot find it.
so in ES6 do I still need libraries like jquery/lodash etc to make web service calls? or can I make such calls using just the new language constructs?
Sorry if this is FAQ. I will delete the question if its very monly asked... but I have really tried searching and found nothing. But I am very sure that I read somewhere that now we can call the REST endpoint directly without any external library.
I was reading a tutorial on the web on ES6 and I am pretty sure that I read that there is a native way to call REST Web services by using ES6.
Now I am googling on that topic and I just cannot find it.
so in ES6 do I still need libraries like jquery/lodash etc to make web service calls? or can I make such calls using just the new language constructs?
Sorry if this is FAQ. I will delete the question if its very monly asked... but I have really tried searching and found nothing. But I am very sure that I read somewhere that now we can call the REST endpoint directly without any external library.
Share Improve this question edited Aug 6, 2017 at 18:13 Ali Mamedov 5,2563 gold badges38 silver badges51 bronze badges asked Feb 3, 2016 at 5:15 Knows Not MuchKnows Not Much 31.6k66 gold badges207 silver badges393 bronze badges 3- 3 "The XMLHttpRequest object is the ECMAScript HTTP API." – Raymond Chen Commented Feb 3, 2016 at 5:25
- 1 There is no EC6. Did you mean ES6? Where does this e from, I've heard it from so many people now? – Bergi Commented Feb 3, 2016 at 5:42
- The XMLHttpRequest object is the ECMAScript HTTP API. - Yeah, so I thought too. But the very link you supply says otherwise. Both the Fetch Standard and the XMLHttpRequest Standard were created by the Web Hypertext Application Technology Working Group (WHATWG) which was formed in June 2004. Hence, neither Fetch nor XMLHttpRequest are ECMAScript constructs. However, plain JavaScript can access the corresponding objects in modern web browsers. – Henke - Нава́льный П с м Commented May 14, 2021 at 12:48
2 Answers
Reset to default 5ES6 (aka ES 2015) does not have a new API that makes consuming REST services any easier than it had been previously.
I suspect you might be looking for the new DOM API that aims to replace XMLHttpRequest called fetch. Only Chrome and Firefox implement this API at the time of this writing: http://caniuse./#feat=fetch
The fetch
API can be polyfilled, here's a good one: https://github./github/fetch
More info on the fetch API: https://developer.mozilla/en-US/docs/Web/API/Fetch_API http://github.github.io/fetch/
Basic usage:
fetch('https://api.github./users')
.then(response => response.json())
.then(users => console.log(users));
Does ecmascript 6 have a native way to call REST Web Services
To answer your question directly: no.
ECMAScript itself has a very limited standard library. It doesn't provide any I/O APIs. Any I/O APIs are provided by the host environment, such as Node or the browser. Those pretty much evolve independently of ECMAScript.
You can find the spec here: http://www.ecma-international/ecma-262/6.0/ .
But I am very sure that I read somewhere that now we can call the REST endpoint directly without any external library.
Depends on the environment. Browsers have supported XMLHTTPRequest
for ages. jQuery is merely a wrapper around that API, so there was never a requirement to use jQuery. jQuery cannot do anything that the browser environment cannot.
Node provides http.request
.
本文标签: javascriptDoes ECMAScript 6 have a native way to call REST Web ServicesStack Overflow
版权声明:本文标题:javascript - Does ECMAScript 6 have a native way to call REST Web Services - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741852871a2401173.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论