Skip to content

Commit

Permalink
adds http docs + fixes generate history json
Browse files Browse the repository at this point in the history
  • Loading branch information
JackDevAU committed Dec 11, 2023
1 parent d3faa9f commit 3795ab0
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public async Task<HttpResponseData> Run(
}));

var responseMessage = JsonConvert.SerializeObject(ruleHistory);

return req.CreateJsonResponse(responseMessage);
return await req.SendJsonResponse(responseMessage);
}
}
2 changes: 1 addition & 1 deletion SSW.Rules.AzFuncs/Functions/Widget/GetLatestRules.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public async Task<HttpResponseData> Run(

var filteredRulesList = filteredRules.ToList();
return filteredRulesList.Count == 0
? req.CreateJsonErrorResponse(HttpStatusCode.NotFound)
? req.CreateJsonErrorResponse(HttpStatusCode.NotFound, "Not Found")
: req.CreateJsonResponse(filteredRules);
}
}
18 changes: 18 additions & 0 deletions SSW.Rules.AzFuncs/helpers/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,24 @@ public static HttpResponseData CreateJsonResponse(this HttpRequestData req, obje
return response;
}


/// <summary>
/// Create a JSON object response
/// </summary>
/// <param name="req"></param>
/// <param name="statusCode">Default 200</param>
/// <param name="message">Default empty</param>
/// <returns></returns>
public static async Task<HttpResponseData> SendJsonResponse(this HttpRequestData req, string message, HttpStatusCode statusCode = HttpStatusCode.OK)
{

var response = req.CreateResponse(statusCode);
response.Headers.Add("Content-Type", "application/json");
response.StatusCode = statusCode;
await response.WriteStringAsync(message);
return response;
}

public static async Task<NameValueCollection> ReadFormDataAsync(this HttpRequestData req)
{
using var reader = new StreamReader(req.Body);
Expand Down
35 changes: 35 additions & 0 deletions docs/Functions/Functions.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
@BaseApiUrl = http://localhost:7071/api

# Health
GET {{BaseApiUrl}}/HealthCheckFunction
Content-Type: application/json

###
# History - Generate
GET {{BaseApiUrl}}/GenerateHistoryFileFunction
Content-Type: application/json

###
# History - SyncCommitHash
GET {{BaseApiUrl}}/GetHistorySyncCommitHash
Content-Type: application/json


###
# Widget - Get LatestRules (with GitHub)
@skip = 0
@take = 10
@githubUsername = ""

GET {{BaseApiUrl}}/GetLatestRules?skip={{skip}}&take={{take}}&githubUsername={{githubUsername}}
Content-Type: application/json

###
# Widget - Get LatestRules (No GitHub)

GET {{BaseApiUrl}}/GetLatestRules?skip={{skip}}&take={{take}}
Content-Type: application/json


###
# Widget - Update LatestRules

0 comments on commit 3795ab0

Please sign in to comment.