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

url_for api generated endpoints #274

Closed
michaelfillier opened this Issue Jan 11, 2014 · 4 comments

Comments

Projects
None yet
3 participants
@michaelfillier

michaelfillier commented Jan 11, 2014

I needed to create a custom route for some complex logic in the app, I am actually returning a 303 since the endpoint performs an update on another object. A 303 is supposed to return a location for the browser or client to know the url of the updated resource, which they can then use to request the object, if needed.

I would like to return the url of the updated object and thought it would be nice to have a shortcut to the GET SINGLE url for the resource. How do you normally refer to your endpoint urls when referring to them throughout your app? Typing them out is simple enough, but if the urls change, whether via an updated prefix or perhaps a model name change, it would be nice if I could simply refer to the endpoint by name and pass in the id, eg api_endpoint(people_get_single, 1).

Any thoughts?

@jfinkels

This comment has been minimized.

Owner

jfinkels commented Jan 14, 2014

I think this would be a fabulous feature. Unfortunately, I'm not really sure where to start, since all the state is maintained in the API class and I'm not sure how to access that information from a module-level function. It would require some digging and experimentation with the flask.url_for function.

@sholsapp

This comment has been minimized.

sholsapp commented Jun 27, 2014

+1 this feature.

@jfinkels wouldn't accessing this information be relatively straight forward? It seems we would just need to expose some methods on https://github.com/jfinkels/flask-restless/blob/master/flask_restless/manager.py#L33. The part that is confusing me is how we would provide an endpoint to the flask.url_for function. Because that requires a function name (or view function?), I'm struggling to find a way to satisfy that API.

Thoughts?

@jfinkels

This comment has been minimized.

Owner

jfinkels commented Jul 15, 2014

Perhaps someone can ask on the Flask mailing list for more info on how to expose URL endpoints this way? (I'm not subscribed to it...)

jfinkels added a commit that referenced this issue Feb 11, 2015

Adds a url_for() function.
The function `url_for()` returns the URL for a model after it's API has
been created via an invocation of `create_api_blueprint()`.

Fixes issue #274.
@jfinkels

This comment has been minimized.

Owner

jfinkels commented Feb 11, 2015

This is implemented in 905b4d6. I'm positive there will be some bugs with it, so please test it out.

@jfinkels jfinkels closed this Feb 11, 2015

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