MXS-1390: Add missing self-link to module command output
The module commands now produce functional self-links. The links most often require parameters so they are not of great use.
This commit is contained in:
@ -39,16 +39,30 @@ MXS_BEGIN_DECLS
|
|||||||
/**
|
/**
|
||||||
* @brief Create a JSON object
|
* @brief Create a JSON object
|
||||||
*
|
*
|
||||||
* The caller should add a `data` field to the returned object.
|
|
||||||
*
|
|
||||||
* @param host Hostname of this server
|
* @param host Hostname of this server
|
||||||
* @param self Endpoint of this resource
|
* @param self Endpoint of this resource
|
||||||
* @param data The JSON data, either an array or an object
|
* @param data The JSON data, either an array or an object, stored in
|
||||||
|
* the `data` field of the returned object
|
||||||
*
|
*
|
||||||
* @return A valid top-level JSON API object
|
* @return A valid top-level JSON API object
|
||||||
*/
|
*/
|
||||||
json_t* mxs_json_resource(const char* host, const char* self, json_t* data);
|
json_t* mxs_json_resource(const char* host, const char* self, json_t* data);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Create a JSON metadata object
|
||||||
|
*
|
||||||
|
* This should be used to transport non-standard data to the client.
|
||||||
|
*
|
||||||
|
* @param host Hostname of this server
|
||||||
|
* @param self Endpoint of this resource
|
||||||
|
* @param data The JSON data, either an array or an object, stored in
|
||||||
|
* the `meta` field of the returned object
|
||||||
|
*
|
||||||
|
* @return A valid top-level JSON API object
|
||||||
|
*/
|
||||||
|
json_t* mxs_json_metadata(const char* host, const char* self, json_t* data);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Create an empty relationship object
|
* @brief Create an empty relationship object
|
||||||
*
|
*
|
||||||
|
@ -39,6 +39,14 @@ json_t* mxs_json_resource(const char* host, const char* self, json_t* data)
|
|||||||
return rval;
|
return rval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
json_t* mxs_json_metadata(const char* host, const char* self, json_t* data)
|
||||||
|
{
|
||||||
|
json_t* rval = json_object();
|
||||||
|
json_object_set_new(rval, CN_LINKS, self_link(host, self));
|
||||||
|
json_object_set_new(rval, CN_META, data);
|
||||||
|
return rval;
|
||||||
|
}
|
||||||
|
|
||||||
json_t* mxs_json_relationship(const char* host, const char* endpoint)
|
json_t* mxs_json_relationship(const char* host, const char* endpoint)
|
||||||
{
|
{
|
||||||
json_t* rel = json_object();
|
json_t* rel = json_object();
|
||||||
|
@ -667,14 +667,15 @@ HttpResponse cb_modulecmd(const HttpRequest& request)
|
|||||||
{
|
{
|
||||||
if (output)
|
if (output)
|
||||||
{
|
{
|
||||||
rc = MHD_HTTP_OK;
|
/**
|
||||||
|
* Store the command output in the meta field. This allows
|
||||||
/** Store the command output in the meta field. This allows
|
|
||||||
* all the commands to conform to the JSON API even though
|
* all the commands to conform to the JSON API even though
|
||||||
* the content of the field can vary from command to command. */
|
* the content of the field can vary from command to command.
|
||||||
json_t* obj = json_object();
|
*/
|
||||||
json_object_set_new(obj, CN_META, output);
|
rc = MHD_HTTP_OK;
|
||||||
output = obj;
|
std::string self = "/"; // The uri_segment doesn't have the leading slash
|
||||||
|
self += request.uri_segment(0, request.uri_part_count());
|
||||||
|
output = mxs_json_metadata(request.host(), self.c_str(), output);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user