pagekit / vue-resource

The HTTP client for Vue.js
MIT License
10.09k stars 1.6k forks source link

Using Http module outside of Vue? #363

Open adamwathan opened 8 years ago

adamwathan commented 8 years ago

Is there any way to use just vue-resource in a project only to take advantage of the HTTP client? It's by far the nicest API I've worked with when it comes to making AJAX requests and seems pretty lightweight.

My use case is working on a little non-UI related library that needs to make a couple AJAX calls, and shockingly the best thing out there it seems is fetch, which is awful! :) Would love if it was possible to import just the HTTP module from vue-resource and use that instead.

steffans commented 8 years ago

Im sorry, not yet. I will keep this in mind for a future version.

sqal commented 8 years ago

@adamwathan Have you tried https://github.com/mzabriskie/axios ? The API looks similar to vue-resource

adamwathan commented 8 years ago

@sqal Did end up finding that and am using it happily, would say it's ok to close this, axios seems great for my use case 👍🏻

kristianmandrup commented 8 years ago

Why not use the Fetch API from HTML5??

adamwathan commented 8 years ago

@kristianmandrup Requires a polyfill since the browsers support is quite there yet, and has some API decisions I really hate.

The main one is that they provide no way to make a GET request and specify the query parameters in a structured way, like Axios does:

axios.get('/user', {
    params: {
      ID: 12345
    }
  })

With Fetch, you need to build the query string yourself, which means worrying about escaping data or pulling in another library to do it. Whole thing is a complete pain in the ass compared to something like Axios, which just has a awesome and usable API right out of the box.

kristianmandrup commented 8 years ago

Good to know thanks. I agree regarding a more intuitive developer oriented API ;) Perhaps the API though could optionally be made to wrap the native Fetch API if present in the browser and fallback to good old XMLHttpRequest if not?