I like all of the functions of Restangular for AngularJS, except that I can't find (and it may not support) a way of just passing a full URL to it. I realize the benefit of the .one('something','someparam') but my issue is that I'm passed various URL strings, and I really don't want to have to split() them just to use Restangular.
Also, I know about the baseURL function; but these URLs I'm being passed don't necessarily derive from the same base path.
For example, I might have:
/us/en/product/17726
/us/es/products
/us/es/product/991A0
/ca/en/accounts
All I'm given are the Strings...
I'm the creator of Restangular.
You have 2 options to do that.
1) Creating scoped Restangulars with different BaseURLs in each case: https://github.com/mgonto/restangular#how-to-create-a-restangular-service-with-a-different-configuration-from-the-global-one
2) You can use it like Restangular.all('us/en/').one('products', 1726) or Restangular.one('us/en/product', 1234)
Hope it works for you :)
I needed to simply GET an absolute url and came across this question.
Here's how:
Restangular.oneUrl('routeName', 'http://absolute.url').get();
restangular#restangular-methods
Related
I want to manually construct URL from parts using the URL object.
However, it's constructor requires a proper URL string to be passed to it, which doesn't allow to start from empty object and build it progressively.
Is there a way to overcome this limitation somehow?
What caused such design decision in the first place?
You have already figured out the workaround and there is no alternative other than passing the parts in or starting with a URL and mutating it.
I'll try to answer:
What caused such design decision in the first place?
By far the most common use case for URLs was to create a URL from a URL string. Someone actually did end up asking for the API you are describing in the URL spec and discussion mostly stalled.
We have an API in Node.js for constructing URLs from parts - but that creates a string one would still need to pass to the URL constructor.
So this is likely not a bad idea and it is currently blocked on someone actually doing the work of adding that capability.
The only workaround I've found so far is to use minimal correct URL to initialize the object and then to override it's parts (namely protocol and host).
const url = new URL('https://example.com');
url.protocol = 'http';
url.host = 'google.com';
console.log(url.toString()); // outputs: http://google.com/
However, it's still cumbersome for this use case.
I want to be able to use get methods in my MEAN API, i have the following code in my index.js:
router.route('/platillos/:id')
.get(PlatilloCtrl.getPlatillosById)
.post(upload.array(),PlatilloCtrl.addComentario)
.put(upload.array(),PlatilloCtrl.updatePlatillo)
.delete(PlatilloCtrl.deletePlatillo);
and I made this one too:
router.route('/platillosC/:categoria')
.get(PlatilloCtrl.getPlatillosByCategoria);
I would like to have the category and the id in the same URI withouth having an extra one.
Is there a way to do this?
Without knowing exactly what you're using in terms of a routing solution, most libraries will accept and parse multiple parameters, ie:
router.route('/platillosC/:id/:categoria')
In some projects I noticed that javascripts included into HTML like this:
<script type="text/javascript" src="./js/score.js?x"></script>
What's mean last 'x' symbol?
It is a query string which may be used to pass variables to the script.
It will help to overcome cache problems as well.
If I had to guess, I would say the X is being used as a querystring fragment. Unless the server is depending on the fragment being there, it could possibly be used as a cache buster.
Essentially, by changing that X to a Y we could make the browser fetch a fresh copy. This is useful if you need to make sure users get a new copy of a file.
Of course, without talking to the author we are just guessing. Perhaps the server needs it there to properly build the file in the first place. Or maybe the javascript itself is using it.
It is not a symbol. It is a piece of query string like on web scripts it would be something like test.php?reload=true
Such techniques might be helpful to overcome the caching problem as mentioned by SLaks on the comments.
You can pass parameters to your javascript.
It can be used to initiliaze variable or be used somewhere.
Take a look at this link http://feather.elektrum.org/book/src.html
I need help because I am trying to create a lib with javascript in order to create, modify, delete params in my url, I explain :
www.mydomain.com/thing/?id=1&et=67&type=chercher
How u can see, my params are random, it's dynamic, It's not every time the same url, I had this url, one time I can have ?id=1&et=67&type=chercher and other time I can have ?id=1&type=chercher or for example just ?id=1 or others params.
So it's not easy because of user action, the url with params will change, so is there an lib or an application written with javascript which can do this easily ?
Thx everyOne for your futures responses !!!!
You are creating a library to manipulate URLs? Have you had a look at the existing solutions?
URI.js is something I can recommend. In its Readme URI.js links to a bunch of alternative solutions you could look into as well.
Yes, absolutely. You can use the jQuery URL Parser plugin. Just make sure you include also jQuery in your page and not only the plugin.
Do u need library which manipulate URL string?
pass associative array(HASH) to function {a:2, b:3, c:4} and then go through this hash and form string.
Is this what u need?
To update - split string by & and downparse into HASH, and replace value by H['a'] = 4;
To delete - delete H["a"];
But better do not reinvent bicycle use tested solutions: http://code.google.com/p/jsuri/
Does anyone have a good solution for getting and setting variables in window.location.hash?
Take a URL that looks like this:
domain.com/#q=1&s=2
What I'd like is an unstressful way - JavaScript or jQuery - to check the values of q and s when the page loads, and change them following events on the page.
I have found some code for getting hash variables, but nothing sensible for setting them.
Am I missing something really obvious, or do I need to roll my own solution (and release it!)?
Thanks.
Haven't used it but there is jHash
jHash allows you to work with the
'location.hash' value in a similar
fashion to a server-side query string.
This library utilizes the HTML5
"onhashchange" event, but also
includes a fall back to still allow
the change notifications to work
properly in older web browsers.
jQuery BBQ can do this.
See also:
Get URL parameter with jQuery
Get QueryString values with jQuery
Edit as #gonchuki points out, jQuery.query can also do this.
JHash didn't work for me in that I wanted it to trigger the routes right away. I personally used routie instead.
It lets you do advanced routing just like jHash but will trigger on page load correctly.
Below will match example.com/#users/john
routie('users/:name', function(name) {
//name == 'bob';
});