0

Are there are any good simple examples of sending http requests with data from reactjs/flux to nodejs and from the nodejs server sending back an HTTP response with data? I was able to do this in AngularJS with Nodejs since it had a $http service but am confused on how to do this with reactjs. Any help is appreciated.

user3226932
  • 2,042
  • 6
  • 39
  • 76
  • 1
    React's own documentation uses jQuery to make the AJAX call and for jQuery there are literaly milions of examples. If you want to use VannilaJS there's a lot of examples too. React doesn't have anything built-in so it's up to you want you use. jQuery http://stackoverflow.com/questions/29990809/handling-ajax-with-react – Molda Mar 19 '16 at 18:01
  • can I use React with vanillaJS? and would you recommend using VanillaJS over jQuery for faster performance? – user3226932 Mar 19 '16 at 18:12
  • I would use jQuery because it makes life a lot easier but the choice is yours. You are free to use anything. It's a shame react doesn't offer anything like $http or $.ajax but in the other hand it gives you freedom to use whatever you like which might actually be better then forcing you to use something you might not like. And angular uses jQuery under the hood too. – Molda Mar 19 '16 at 18:17
  • 1
    Just a reminder that React is a library for rendering views, not a do-it-all-framework. Implement whatever AJAX method you wish to use. The native javascript Fetch API is more than good enough, just add the polyfill, because it's not widely supported yet. – dannyjolie Mar 19 '16 at 20:32

1 Answers1

1

ReactJS does not come with a http service like you have in AngularJS. That is the way they keep their Library lean.

For making http requests, you can use:

  • JQuery (Most advised, as its the most used library on the frontend and probably your project or theme is already using it, so no need to include any new library).
  • Axios, really nice implementation of the Promise API and Client side support for protecting against XSRF (plus supports IE8)
  • Fetch, built by Github so support is pretty good
  • Superagent, small, easy to use and easily extensible via plugins
Anil Konsal
  • 151
  • 2
  • 11