Pretty print all JSON responses from REST API

Bug #1664328 reported by Jim Baker
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
craton
Fix Released
High
git-harry

Bug Description

For better demo/human usage of the REST API, and to follow fairly common practice, we should always pretty print the JSON responses. This adds negligible overhead: the JSON encoder in the json library has virtually no overhead for adding indentation; and gzip encoding would take care of this and other JSON encoding overhead issues in terms of resulting size.

This should be a few line fix, per http://flask-restful-cn.readthedocs.io/en/0.3.5/extending.html#content-negotiation

For the specific pretty printing, I suggest we use {"indent": 2, "sort_keys": True} (such sorting is also negligible in cost, especially given pagination).

Jim Baker (jimbaker)
description: updated
Changed in craton:
importance: Undecided → High
milestone: none → v0.1.0
git-harry (git-harry)
Changed in craton:
assignee: nobody → git-harry (git-harry)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to craton (master)

Fix proposed to branch: master
Review: https://review.openstack.org/442588

Changed in craton:
status: New → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to craton (master)

Reviewed: https://review.openstack.org/442588
Committed: https://git.openstack.org/cgit/openstack/craton/commit/?id=0f7ee6d79189b2d8c5a81cf9e9598f96575f511d
Submitter: Jenkins
Branch: master

commit 0f7ee6d79189b2d8c5a81cf9e9598f96575f511d
Author: git-harry <email address hidden>
Date: Tue Mar 7 15:33:08 2017 +0000

    Pretty-print format all JSON response bodies

    Flask-RESTful automatically converts a response body to JSON when it
    creates the Response object. The Flask app configuration option
    RESTFUL_JSON is added by this commit to appropriately modify how the
    JSON body is constructed.

    response_filter has been modified so that it returns a tuple of
    information that Flask-RESTful will use to create an appropriately
    formatted response.

    Resource.error_response is creating the Response object itself and so
    has been modified to format the JSON in the same way as Flask-RESTful.
    Ideally, error_response would not create a separate Response object
    however addressing this is a separate issue.

    Change-Id: I02eafaf48d7c6e2ceab0add2f78cf6aa1b890f18
    Closes-bug: 1664328

Changed in craton:
status: In Progress → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.