Rework API to be more RESTful (references #139)

This commit is contained in:
Bernd Bestel
2019-01-19 14:51:51 +01:00
parent 0ce8d706a6
commit bfa59dd29c
52 changed files with 1110 additions and 1143 deletions

View File

@@ -125,11 +125,18 @@ Grocy.Api.Get = function(apiFunction, success, error)
{
if (xhr.readyState === XMLHttpRequest.DONE)
{
if (xhr.status === 200)
if (xhr.status === 200 || xhr.status === 204)
{
if (success)
{
success(JSON.parse(xhr.responseText));
if (xhr.status === 200)
{
success(JSON.parse(xhr.responseText));
}
else
{
success({ });
}
}
}
else
@@ -155,11 +162,18 @@ Grocy.Api.Post = function(apiFunction, jsonData, success, error)
{
if (xhr.readyState === XMLHttpRequest.DONE)
{
if (xhr.status === 200)
if (xhr.status === 200 || xhr.status === 204)
{
if (success)
{
success(JSON.parse(xhr.responseText));
if (xhr.status === 200)
{
success(JSON.parse(xhr.responseText));
}
else
{
success({ });
}
}
}
else
@@ -186,11 +200,18 @@ Grocy.Api.Put = function(apiFunction, jsonData, success, error)
{
if (xhr.readyState === XMLHttpRequest.DONE)
{
if (xhr.status === 200)
if (xhr.status === 200 || xhr.status === 204)
{
if (success)
{
success(JSON.parse(xhr.responseText));
if (xhr.status === 200)
{
success(JSON.parse(xhr.responseText));
}
else
{
success({ });
}
}
}
else
@@ -217,11 +238,18 @@ Grocy.Api.Delete = function(apiFunction, jsonData, success, error)
{
if (xhr.readyState === XMLHttpRequest.DONE)
{
if (xhr.status === 200)
if (xhr.status === 200 || xhr.status === 204)
{
if (success)
{
success(JSON.parse(xhr.responseText));
if (xhr.status === 200)
{
success(JSON.parse(xhr.responseText));
}
else
{
success({ });
}
}
}
else
@@ -386,7 +414,7 @@ $(".user-setting-control").on("change", function()
jsonData = { };
jsonData.value = value;
Grocy.Api.Post('user/settings/' + settingKey, jsonData,
Grocy.Api.Put('user/settings/' + settingKey, jsonData,
function(result)
{
// Nothing to do...