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

Consider an option for an explicit list of allowed methods #555

Open
muodov opened this issue Jun 4, 2015 · 5 comments
Open

Consider an option for an explicit list of allowed methods #555

muodov opened this issue Jun 4, 2015 · 5 comments

Comments

@muodov
Copy link
Contributor

muodov commented Jun 4, 2015

Currently, routing code would allow all methods the responders are implemented for. But this behavior makes it inconvenient if one wants to inherit the resource class. The only way to disallow method in a child class is to override all the responders which results in a bunch of useless code.

It would be nice to be able to set some resource attribute to a list of allowed methods.

@muodov muodov changed the title considering a property for a list of allowed methods Consider an option for an explicit list of allowed methods Jun 4, 2015
@kgriffs
Copy link
Member

kgriffs commented Jun 16, 2015

@muodov thanks for the feedback. I'd like to learn more about how you are using inheritance. Could you provide more details on your use case?

@muodov
Copy link
Contributor Author

muodov commented Jun 17, 2015

@kgriffs Sure. In our application we store objects in mongodb, so in the code we have a base class called DocumentResource which handles all communication with the database. The base class accepts a collection name as an argument and it can get, put, and post objects.
Now, for specific documents we subclass DocumentResource and place the document-specific logic in there. The problem is, we want to provide different sets of actions for different kinds of objects. For example, we need to allow only GET method. In this case we need to explicitly override the parent methods for other HTTP methods so that they set falcon.HTTP_METHOD_NOT_ALLOWED status. This results in a lot of copypasted code and generally is quite error prone.

@pior
Copy link

pior commented Jul 27, 2015

What about:

class MyResource(DocumentResource):
    model = Foo
    on_put = NotImplemented  # https://docs.python.org/2/library/constants.html#NotImplemented

I may also need this. For a similar resource subclass pattern.

@kgriffs
Copy link
Member

kgriffs commented May 19, 2016

Another option. This would override the default behavior of allowing all HTTP methods that have a corresponding on_* responder defined.

class SomeResource(DocumentResource):
    allow = ['GET']

@kgriffs kgriffs added this to the On Deck (Non-Breaking Changes) milestone May 19, 2016
@muodov
Copy link
Contributor Author

muodov commented May 19, 2016

@kgriffs I like your suggestion. It feels more natural for people coming from other frameworks, since they have similar concepts.

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

No branches or pull requests

3 participants