最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Does ECMAScript 6 have a native way to call REST Web Services - Stack Overflow

programmeradmin0浏览0评论

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
Add a ment  | 

2 Answers 2

Reset to default 5

ES6 (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.

发布评论

评论列表(0)

  1. 暂无评论