[WIP] API Explorer back-end
Review Request #7904 — Created Jan. 24, 2016 and discarded
An API Explorer allows developers to make requests to the Web API from their browsers without having to download XML or JSON files. The API Explorer will display the response as syntax highlighted JSON in order to be understandable and facilitate development and understanding of the Web API.
In the future, users will be able to make POST, PUT and DELETE requests from a provided form and view documentation related to the resource.
This patch focuses on creating an HTML Encoder that will retrieve the payload and determine the resource being accessed.
Modifications to the way the Web API handles requests are also made to ensure that requests can also be made from a web browser.
Tested /api/users/<user_name> and /api/users/ which returned the correct information, in the proper format which displayed correctly in a web browser.
Description | From | Last Updated |
---|---|---|
Two blank lines between these. |
brennie | |
This should have: from __future__ import unicode literals |
brennie | |
Docstring? |
brennie | |
Alphabetize. |
brennie | |
Docstring. |
brennie | |
Docstring. |
brennie | |
Docstring. |
brennie | |
Can we reforamt this as: return render_to_string( 'webapi/explorer.html', { 'payload': o, }) |
brennie | |
Single quotes for strings. |
brennie | |
Alphabetize these. |
brennie | |
Can you change all these to use single quotes? |
brennie | |
Please format this as: if (self.mimetype == 'text/plain' or is_mimetype_a(self.mimetype, 'application/json')): # ... |
brennie | |
Can you change this to all use single quotes? |
brennie | |
Single quotes. |
brennie | |
We already import json above. Lets just use json.dumps. |
brennie | |
So our import layout is as follows: from __future__ import unicode_literals # Always first. # Standard library imports. import json … |
brennie | |
'datetime' imported but unused |
reviewbot | |
Col: 80 E501 line too long (86 > 79 characters) |
reviewbot | |
'Directive' imported but unused |
reviewbot | |
Col: 80 E501 line too long (110 > 79 characters) |
reviewbot | |
Col: 80 E501 line too long (110 > 79 characters) |
reviewbot | |
Col: 80 E501 line too long (113 > 79 characters) |
reviewbot | |
Col: 80 E501 line too long (113 > 79 characters) |
reviewbot | |
Col: 80 E501 line too long (110 > 79 characters) |
reviewbot | |
Col: 80 E501 line too long (110 > 79 characters) |
reviewbot | |
Col: 80 E501 line too long (113 > 79 characters) |
reviewbot | |
Col: 80 E501 line too long (113 > 79 characters) |
reviewbot |
- Depends On:
- Change Summary:
-
Added support for viewable responses from a web browser.
- Description:
-
~ -Added support for api requests made by web browsers to return HTML.
~ An API Explorer allows developers to make requests to the Web API from their browsers without having to download XML or JSON files. The API Explorer will display the response as syntax highlighted JSON in order to be understandable and facilitate development and understanding of the Web API.
+ + In the future, users will be able to make POST, PUT and DELETE requests from a provided form and view documentation related to the resource.
+ + This patch focuses on creating an HTML Encoder that will retrieve the payload and determine the resource being accessed.
- Testing Done:
-
~ Tested /api/users/<user_name> with and without a user specified.
~ Tested /api/users/<user_name> and /api/users/ which returned the correct information, in the proper format which displayed correctly in a web browser.
- - Unit tests succeeded.
-
Tool: PEP8 Style Checker Processed Files: djblets/util/templatetags/djblets_webapi.py djblets/webapi/responses.py djblets/webapi/encoders.py Tool: Pyflakes Processed Files: djblets/util/templatetags/djblets_webapi.py djblets/webapi/responses.py djblets/webapi/encoders.py
- Depends On:
-
Tool: Pyflakes Processed Files: djblets/util/templatetags/djblets_webapi.py djblets/webapi/responses.py djblets/webapi/encoders.py Tool: PEP8 Style Checker Processed Files: djblets/util/templatetags/djblets_webapi.py djblets/webapi/responses.py djblets/webapi/encoders.py
-
-
-
So our import layout is as follows:
from __future__ import unicode_literals # Always first. # Standard library imports. import json from xml.foo import bar # 3-rd party library imports. from django.conf import settings # ... from pygments import hilight # Our current project imports from djblets import foobar
We put full imports
import foo
above partial imports (from foo import bar
),
- Change Summary:
-
-Updated encoder to strictly handle encoding the payload for HTML responses
-Added support for handling API responses in 'text/html' format.
-Added support for displaying the payload
-Removed template tag that is no longer used.
-
Tool: Pyflakes Processed Files: djblets/util/templatetags/djblets_webapi.py djblets/webapi/resources/base.py djblets/webapi/responses.py djblets/webapi/encoders.py Tool: PEP8 Style Checker Processed Files: djblets/util/templatetags/djblets_webapi.py djblets/webapi/resources/base.py djblets/webapi/responses.py djblets/webapi/encoders.py
- Change Summary:
-
-Added support for passing resource fields to the template
-Added basic type handling for resource fields being passed to the template
-Updated HTML encoder to properly encode all resource types
-
Tool: Pyflakes Processed Files: djblets/util/templatetags/djblets_webapi.py djblets/webapi/resources/base.py djblets/webapi/responses.py djblets/webapi/encoders.py Tool: PEP8 Style Checker Processed Files: djblets/util/templatetags/djblets_webapi.py djblets/webapi/resources/base.py djblets/webapi/responses.py djblets/webapi/encoders.py
-
-
-
- Change Summary:
-
-Added support for differentiation between required and optional fields
-Added support for fields of different request types
-Removed extraneous imports
-Proper formatting
-Removed unused template tag
-
Tool: Pyflakes Processed Files: djblets/webapi/resources/base.py djblets/webapi/responses.py djblets/webapi/encoders.py Tool: PEP8 Style Checker Processed Files: djblets/webapi/resources/base.py djblets/webapi/responses.py djblets/webapi/encoders.py
-
-
-
-
-
Tool: Pyflakes Processed Files: djblets/webapi/resources/base.py djblets/webapi/responses.py djblets/webapi/encoders.py Tool: PEP8 Style Checker Processed Files: djblets/webapi/resources/base.py djblets/webapi/responses.py djblets/webapi/encoders.py
-
-
-
-
- Change Summary:
-
-Added support for only displaying the payload response of a GET request made by the front-end
-Added support for handling resources that have no optional or required fields for GET requests
-
Tool: Pyflakes Processed Files: djblets/webapi/resources/base.py djblets/webapi/responses.py djblets/webapi/encoders.py Tool: PEP8 Style Checker Processed Files: djblets/webapi/resources/base.py djblets/webapi/responses.py djblets/webapi/encoders.py
-
Tool: Pyflakes Processed Files: djblets/webapi/resources/base.py djblets/webapi/responses.py djblets/webapi/encoders.py Tool: PEP8 Style Checker Processed Files: djblets/webapi/resources/base.py djblets/webapi/responses.py djblets/webapi/encoders.py
- Change Summary:
-
- Updated how HTML request types are handled to the API
- Updated how standard http response types are handled
-
Tool: Pyflakes Processed Files: djblets/webapi/resources/base.py djblets/webapi/responses.py djblets/webapi/encoders.py Tool: PEP8 Style Checker Processed Files: djblets/webapi/resources/base.py djblets/webapi/responses.py djblets/webapi/encoders.py
- Change Summary:
-
- Updated how HTML request types are handled to the API
- Updated how standard HTTP response types are handled
- Updated how API Explorer template is rendered
- Refactored code
- Description:
-
An API Explorer allows developers to make requests to the Web API from their browsers without having to download XML or JSON files. The API Explorer will display the response as syntax highlighted JSON in order to be understandable and facilitate development and understanding of the Web API.
In the future, users will be able to make POST, PUT and DELETE requests from a provided form and view documentation related to the resource.
This patch focuses on creating an HTML Encoder that will retrieve the payload and determine the resource being accessed.
+ + Modifications to the way the Web API handles requests are also made to ensure that requests can also be made from a web browser.