Comments (6)
Hey @kazzkiq! I'm glad you're enjoying it =)
But, I don't know.. Can you show me a real example for this problem?
The point is: every call to ajax()
function creates a new XMLHttpRequest
instance.
If you want to force a base url, it will be necessary to add a static method on ajax
object, like this:
ajax.baseUrl('http://example.com')
And then, every call to ajax()
would be using this base url. But that seems not the right way to do it xD
I'm thinking about it. Give me a bit of time xD
from ajax.
@fdaciuk Yeah thats exactly what I thought. As ajax()
is a singleton, by setting a baseUrl
you would be changing all the other AJAX calls too.
Thats the biggest downside of this approach. If a developer overrides it from another place, all other devs/AJAX calls are affected too (although I think this can easily be solved with a proper app architecture).
However, as I said, most client-side applications would always consume from the same API, so despite the issue above, it also makes sense to set a baseUrl
as default and only change that on specific cases.
Real example:
Imagine you're building a Twitter client. You're going to enable search, feed, hashtag filters and such. All those actions are under an API that use the same base URL: https://api.twitter.com/1.1/
. The same goes for Facebook, and for other big services, and for mainstream projects too. You generally always consume from the same place. And what if the API changes? Would you need to replace all your ajax()
URLs? Why not just replace the baseUrl()
value and watch it work flawlessly?
If this is not true for some application, the user can simply not register any baseUrl
. However, in most common cases I think it would be useful to configure this baseUrl
on startup and then just use ajax()
omitting the base of the URL.
Of course one could simply create an abstract class which sets an URL and then pass it like:
ajax().get(API.baseUrl + '/etc/abc')
However I think a solution built in the library would aggregate to its value and usability.
from ajax.
Hey @kazzkiq! Sorry for the delay xD
In actual version, this is impossible without cause bugs, because I am using return object with then
, catch
and always
methods as a reference.
But the good news is: I am working in a v2
for this library, in a more functional approach, and I have ever implemented this feature xD
Look here: https://github.com/fdaciuk/ajax/tree/v2.0.0-beta
All tests are passing! If you could test, I really thank you =)
If you are using NPM, just install with npm i --save @fdaciuk/ajax@beta
from ajax.
Hey @fdaciuk , I did a rapid test here and it worked like a charm! Very good! :)
from ajax.
Thanks @kazzkiq 💃 💃 ✨
from ajax.
It was added on v2.0 =)
Thanks for your contribution :D
from ajax.
Related Issues (20)
- Support to withCredentials HOT 1
- Add jsonp method HOT 2
- Error HOT 13
- Add non-minified source on NPM HOT 1
- "Promise" api is not a proper thenable HOT 1
- mothed "GET" no param request. HOT 1
- Get HTML data HOT 1
- Missing character causes error HOT 7
- Add PATCH support HOT 5
- Call blocked: Origin 'null' is therefore not allowed access HOT 1
- Use fetch with XMLHttpRequest fallback? HOT 3
- Browser logos are broken on README HOT 1
- add 'get' data support HOT 1
- Posso trocar o ajaxForm() do jQuery por essa lib? HOT 2
- Send [object object] from method PUT HOT 4
- ES6 / ES2015 module import HOT 1
- Shouldn't 2.3.1 be a new minor version? HOT 3
- Is this ajax use cache? HOT 1
- Error when using method options HOT 4
- content-type: x-www-form-urlencoded error
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ajax.