Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

nyxtom
Copy link

@nyxtom nyxtom commented Apr 4, 2013

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.

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.
@dcneiner
Copy link
Contributor

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

@nyxtom
Copy link
Author

nyxtom commented Apr 10, 2013

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.

@dcneiner
Copy link
Contributor

@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
Copy link
Contributor

Er, not syntax error, just an implied global…

@nyxtom
Copy link
Author

nyxtom commented Apr 10, 2013

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

@nyxtom
Copy link
Author

nyxtom commented Apr 10, 2013

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() }; })

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

Successfully merging this pull request may close these issues.

3 participants