amplify
amplify copied to clipboard
Add support for getting the fully formatted url using amplify.format
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 Can you provide a short code example of how this would be used and the benefit it provides?
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 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?
Er, not syntax error, just an implied global…
There we go, no need to set the callback for that particular context.
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() }; })