1

I'm using Flask-Restless 0.17.0 and having trouble getting a preprocessor or postprocessor function to fire. For reference, I have an SQLAlchemy model that look like:

class Transaction(Base):
    id = Column(Integer, primary_key=True)
    name = Column(Unicode)
    description = Column(Unicode)

I'm able to register the API endpoint without any trouble, but I can not get this hello_world postprocessor to print "hello world" for the life of me:

def hello_world(**kwargs):
    print 'hello world'

manager.create_api(
    fraud.data.Transaction
    methods=['GET', 'POST', 'DELETE'],
    postprocessors={'POST_RESOURCE': [hello_world]},
)

Am I missing something? Any pointers, hints, etc would be greatly appreciated!

dino
  • 3,093
  • 4
  • 31
  • 50

1 Answers1

4

Version 0.17.0 doesn't support POST_RESOURCE. The supported post-processor types appear to be:

  • 'GET_SINGLE' for requests to get a single instance of the model.
  • 'GET_MANY' for requests to get the entire collection of instances of the * model.
  • 'PATCH_SINGLE' or'PUT_SINGLE'` for requests to patch a single instance of the model.
  • 'PATCH_MANY' or 'PATCH_SINGLE' for requests to patch the entire collection of instances of the model.
  • 'POST' for requests to post a new instance of the model.
  • 'DELETE_SINGLE'
  • 'DELETE_MANY'

For your usage, try postprocessors={'POST': [hello_world]}.

References:

Robᵩ
  • 163,533
  • 20
  • 239
  • 308
  • Thanks for your help @Robᵩ. I was looking at the `latest` documentation (the default from google), which apparently changes the API quite a bit. I tried poking around in the source code but was getting lost in my flask n00bness. – dino Feb 11 '16 at 15:10
  • I posted a github issue on the Flask-Restless page to better capture versioning of the documentation. Thanks again for your help https://github.com/jfinkels/flask-restless/issues/485 – dino Feb 11 '16 at 16:46