diff --git a/Documentation/REST-API/API.md b/Documentation/REST-API/API.md index ddb0e2aac..a57ad7646 100644 --- a/Documentation/REST-API/API.md +++ b/Documentation/REST-API/API.md @@ -74,6 +74,9 @@ fields can be added, old ones can be removed and the meaning of existing fields can change. The aim is to be as backwards compatible as reasonably possible without sacrificing the clarity and functionality of the API. +Since MaxScale 2.4.0, the use of the version prefix `/v1/` is optional: if the +prefix is not used, the latest API version is used. + ### Resource Relationships All resources return complete JSON objects. The returned objects can have a diff --git a/server/core/admin.cc b/server/core/admin.cc index d6c7f6bbd..1bf6fc54d 100644 --- a/server/core/admin.cc +++ b/server/core/admin.cc @@ -119,11 +119,8 @@ int Client::process(string url, string method, const char* upload_data, size_t* HttpResponse reply(MHD_HTTP_NOT_FOUND); MXS_DEBUG("Request:\n%s", request.to_string().c_str()); - - if (request.validate_api_version()) - { - reply = resource_handle_request(request); - } + request.fix_api_version(); + reply = resource_handle_request(request); string data; diff --git a/server/core/httprequest.cc b/server/core/httprequest.cc index dd71689b0..386081a35 100644 --- a/server/core/httprequest.cc +++ b/server/core/httprequest.cc @@ -82,21 +82,12 @@ HttpRequest::~HttpRequest() { } -bool HttpRequest::validate_api_version() +void HttpRequest::fix_api_version() { - bool rval = false; - - if (m_resource_parts.empty()) - { - rval = true; - } - else if (m_resource_parts[0] == MXS_REST_API_VERSION) + if (!m_resource_parts.empty() && m_resource_parts[0] == MXS_REST_API_VERSION) { m_resource_parts.pop_front(); - rval = true; } - - return rval; } namespace diff --git a/server/core/internal/httprequest.hh b/server/core/internal/httprequest.hh index ab7283b97..482ac1ad1 100644 --- a/server/core/internal/httprequest.hh +++ b/server/core/internal/httprequest.hh @@ -285,7 +285,7 @@ public: * * @return True if prefix is present and was successfully removed */ - bool validate_api_version(); + void fix_api_version(); private: