Change JSON Response to Flask-Restless

I am trying to use Flask-Restless with Ember.js, which is not so great. These are the GET responses that turn me off. For example, when I make a request GETfor /api/peopleexample, Ember.js expects:

{ 
    people: [
        { id: 1, name: "Yehuda Katz" }
    ] 
}

But Flask-Restless answers:

{
    "total_pages": 1, 
    "objects": [
        { "id": 1, "name": "Yahuda Katz" }
    ], 
    "num_results": 1, 
    "page": 1
}

How do I modify Flask-Restless's answer to fit what Ember.js would like? I have a feeling that it might be in the postprocessor function, but I'm not sure how to implement it.

+5
source share
2 answers

At that time, the accepted answer was correct. However, mail and preprocessors work in Flask-Restless. According to the documentation :

, ( , ). .

, , . :

def api_post_get_many(result=None, **kw):
    for key in result.keys():
        if key != 'objects':
            del result[key]
+3

. GET_MANY:

def pagination_remover(results):
    return {'people': results['objects']} if 'page' in results else results

manager.create_api(
    ...,
    postprocessors={
        'GET_MANY': [pagination_remover]
    }
)

, .

+8

All Articles