10

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

2 Answers 2

14

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 :)

Sign up to request clarification or add additional context in comments.

3 Comments

That's what I needed. I tried adding the full URL like Restangular.all('/us/en') and it gacked out on me. Must have been that leading slash.
Do you think it would be useful to add a feature that would allow someone to make a one-off request given a string URL so they don't have to process it, or create multiple scoped instances? One of the benefits of this over $resource is that multiple instances are not required for a single request...
Hey, I don't think how much helpfull it'd be. Using it as it's now is pretty similar as you can see because you can use this with URLs as well :).
11

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

4 Comments

What does routeName do here?
@AlirezaMirian I don't have the source that was using this on hand, but if I remember correctly routeName essentially acts as GUID for Restangular routes. The object that is returned from Restangular.oneUrl() doesn't need to know about routeName. Not sure how routeName conflicts are handled...
Watch out: in this form the returned Restangular element has an invalid route, so put() and post() won't work
@itghisi This could cause confusion. If an element is returned, the route is valid but it may not support PUT and POST verbs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.