method to intercept request to rewrite request url #603

Closed
airtonix opened this Issue Mar 2, 2014 · 20 comments

Projects

None yet
@airtonix
Contributor
airtonix commented Mar 2, 2014

This is a question about addRequestInterceptor.

Despite having access to the initial request URL (that is created by the URL builder), it doesn't seem to allow me to change the URL that ends up being used, I could be wrong.

My use case is this :

  • My data is stored as static JSON files on github pages.
  • I use angular
  • I'm building a resource that pulls collections or a single item based on a reference like api/recipe/453

I'd like to transform the request url on the .one(453) from api/recipe/453/data.json to merely api/recipe/data.json then pull out the item with id matching 453 using some lodash.

I feel that addRequestInterceptor meets all but one of those needs (that of rewriting the eventual url used).

Can you clarify if addRequestInterceptor makes it possible to do the following:

  • change the URL used to make the request
  • manipulate the data retrieved with something like lodash
  • use cached data instead of making http requests.
@mgonto
Owner
mgonto commented Apr 25, 2014

Hey,

I think this makes sense.

Marking as enhancement :).

Thanks!

@mgonto mgonto added the enhancement label Apr 25, 2014
@Bclayson

Was this ever done? I am in a similar position and can't figure out how to actually change the request url.

@lucval
lucval commented Jun 17, 2015

Wondering whether this was ever done or planned to be done.. It will be very useful indeed.

@scheeles

1+

@bernyfox
bernyfox commented Jul 8, 2015

+1

@laicosly

+1

@fvezzoso

+1

@TimoSolo

+1

@danibasauri

+1

@abstratt
abstratt commented Sep 8, 2015

+1

@jamespsterling

+1, doesn't appear to work in the addFullRequestInterceptor() method

@fzaninotto

๐Ÿ‘

@ElielBarone

+1

@daurnimator
daurnimator commented Jun 1, 2016 edited

Any progress on this?

This is causing me issues when trying to back ng-admin with postgrest. The style of workaround shown at https://github.com/marmelab/ng-admin-postgrest/blob/master/main.js#L39 doesn't work in the general case.

@daviesgeek
Collaborator

This was done with setRequestSuffix

I'm going to close this for now; feel free to re-open if there's still an issue

@daviesgeek daviesgeek closed this Jun 16, 2016
@daurnimator

setRequestSuffix isn't enough at all.
I need to change the url from /foo/bar?some=query to /foo?id=bar&some=query

(I can't reopen)

@daviesgeek
Collaborator

@daurnimator Your issue is a separate issue than the OP. How about you open up another issue with your specific use case?

@daurnimator

@daurnimator Your issue is a separate issue than the OP. How about you open up another issue with your specific use case?

I can; though there are many blog posts/faqs/stack overflow answers out there that already point to this issue as the relevant one for what I'm asking.

@daviesgeek
Collaborator

@daurnimator While many other external sources may point to this issue, the OP's question was how to append .json to the end of the URL, which was solved. Your specific issue, which I think is completely valid, is how to append parameters to the url, which could also extend to modifying the URL in a more substantial way than just adding a suffix.

It looks like this is already supported (see my Plunk), but if that still doesn't answer your question, please feel free to open another issue

@allentc
allentc commented Jun 24, 2016 edited

@daviesgeek Respectfully, the OP's question was not about appending .json to the end of the URL. The OP provided an illustration of what was intended; changing the path part of the URL from api/recipe/453/data.json to api/recipe/data.json. The OP asked if Restangular permitted one to "change the URL used to make the request" via addRequestInterceptor, not merely the parameters. @daurnimator subsequently asked for the same capability to alter the URL in addRequestInterceptor, not merely the parameters, as in your Plunk example. I believe the issue as written by the OP and others has not been addressed and that the issue should be open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment