amplify icon indicating copy to clipboard operation
amplify copied to clipboard

Add support for getting the fully formatted url using amplify.format

Open nyxtom opened this issue 12 years ago • 6 comments

When you call amplify.request.define, this will ensure that  amplify.request.urls is also set. This allows you to call  amplify.format to get the formatted url based on the endpoint and  data you pass to the callback.

nyxtom avatar Apr 04 '13 23:04 nyxtom

@nyxtom Can you provide a short code example of how this would be used and the benefit it provides?

dcneiner avatar Apr 10 '13 20:04 dcneiner

Sure thing! I currently use it in the following manner:

  window.location = amplify.format("api.requestpdf", { "topic": "xyz", "timeFrom": from, "timeTo": to });

This will produce a formatted url that I currently use to request a pdf download based on an api endpoint without having to manually construct the url. This is nice because I define all my api endpoints in one place so I can simply reuse it, as well as ensure that my urls are getting formatted appropriately for debugging purposes.

nyxtom avatar Apr 10 '13 20:04 nyxtom

@nyxtom Thank you … very interesting use case, I can see how that would be helpful. We need to do some planning around new features in Amplify, so this request may stay open a little bit. There does seem to be a syntax error where you set callback = but its not defined anywhere. Can you fix that?

dcneiner avatar Apr 10 '13 20:04 dcneiner

Er, not syntax error, just an implied global…

dcneiner avatar Apr 10 '13 21:04 dcneiner

There we go, no need to set the callback for that particular context.

nyxtom avatar Apr 10 '13 21:04 nyxtom

Although, if it's a function it could be a callback to obtain the current data. I suppose it depends on the use case. e.g.

amplify.format("api.requestpdf", function () { return { "topic": self.currentTopic() }; })

nyxtom avatar Apr 10 '13 21:04 nyxtom