You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by bm...@apache.org on 2016/02/05 06:18:45 UTC

[5/8] mesos git commit: Added ability to return the /help endpoint as a JSON object.

Added ability to return the /help endpoint as a JSON object.

Previously, the /help endpoint could only be returned as either pure
markdown or html.

This commit introduces a query parameter: format=json to allow the
help endpoint to return a JSON object containing the help information
for all other endpoints.

Review: https://reviews.apache.org/r/43217/


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/b2cefc67
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/b2cefc67
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/b2cefc67

Branch: refs/heads/master
Commit: b2cefc67afc436c38d09de017326e8de986fffe4
Parents: 24fff87
Author: Kevin Klues <kl...@gmail.com>
Authored: Thu Feb 4 19:28:36 2016 -0800
Committer: Benjamin Mahler <be...@gmail.com>
Committed: Thu Feb 4 21:18:17 2016 -0800

----------------------------------------------------------------------
 3rdparty/libprocess/src/help.cpp | 13 +++++++++++++
 1 file changed, 13 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/b2cefc67/3rdparty/libprocess/src/help.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/help.cpp b/3rdparty/libprocess/src/help.cpp
index 85d6bcb..be3f7b7 100644
--- a/3rdparty/libprocess/src/help.cpp
+++ b/3rdparty/libprocess/src/help.cpp
@@ -188,6 +188,19 @@ Future<http::Response> Help::help(const http::Request& request)
   string references;
 
   if (id.isNone()) {             // http://ip:port/help
+    // If the request query string has format=json, return the JSON
+    // representation of the helps strings.
+    //
+    // NOTE: We avoided relying on the 'Accept' header to specify the
+    // format because if users are hitting the endpoint from a browser
+    // it is difficult to change the 'Accept' header.
+    //
+    // TODO(klueska): add the ability for all /help/* endpoints to be
+    // returned as json, not just /help.
+    if (request.url.query.get("format") == Some("json")) {
+      return http::OK(jsonify(*this));
+    }
+
     document += "## HELP\n";
     foreachkey (const string& id, helps) {
       document += "> [/" + id + "][" + id + "]\n";