diff --git a/src/HttpRequestData.Extensions/HttpRequestData.Extensions/HttpRequestData.Extensions.csproj b/src/HttpRequestData.Extensions/HttpRequestData.Extensions/HttpRequestData.Extensions.csproj
index befa025..e5696de 100644
--- a/src/HttpRequestData.Extensions/HttpRequestData.Extensions/HttpRequestData.Extensions.csproj
+++ b/src/HttpRequestData.Extensions/HttpRequestData.Extensions/HttpRequestData.Extensions.csproj
@@ -4,7 +4,7 @@
net5.0
TaleLearnCode.HttpRequestData.Extensions
TaleLearnCode
- 0.0.0-pre
+ 0.0.1-pre
TaleLearnCode
Green Events & Technology, LLC.
HttpRequestData Extensions
diff --git a/src/HttpRequestData.Extensions/HttpRequestData.Extensions/HttpRequestDataExtensions.cs b/src/HttpRequestData.Extensions/HttpRequestData.Extensions/HttpRequestDataExtensions.cs
index 360af71..34521cd 100644
--- a/src/HttpRequestData.Extensions/HttpRequestData.Extensions/HttpRequestDataExtensions.cs
+++ b/src/HttpRequestData.Extensions/HttpRequestData.Extensions/HttpRequestDataExtensions.cs
@@ -16,6 +16,20 @@ namespace TaleLearnCode
public static class HttpRequestDataExtensions
{
+ ///
+ /// Creates a response with the provided body text.
+ ///
+ /// The for this response.
+ /// The HTTP status code to return in the response.
+ /// The text of the response body.
+ /// A representing the response with the in the body.
+ public static HttpResponseData CreateResponse(this HttpRequestData httpRequestData, HttpStatusCode httpStatusCode, string bodyText)
+ {
+ HttpResponseData response = httpRequestData.CreateResponse(httpStatusCode);
+ response.WriteString(bodyText);
+ return response;
+ }
+
///
/// Creates a response with a body for the provided .
///
@@ -79,8 +93,7 @@ public static async Task CreateResponseAsync(
///
/// The for this response.
/// A with a status of Internal Server Error (500).
- public static HttpResponseData CreateErrorResponse(
- this HttpRequestData httpRequestData)
+ public static HttpResponseData CreateErrorResponse(this HttpRequestData httpRequestData)
{
return httpRequestData.CreateResponse(HttpStatusCode.InternalServerError);
}
@@ -91,9 +104,7 @@ public static HttpResponseData CreateErrorResponse(
/// The for this response.
/// The causing the Internal Server Error to be returned.
/// A with a status of Internal Server Error (500) and a response body with the message from .
- public static HttpResponseData CreateErrorResponse(
- this HttpRequestData httpRequestData,
- Exception exception)
+ public static HttpResponseData CreateErrorResponse(this HttpRequestData httpRequestData, Exception exception)
{
if (exception == default) throw new ArgumentNullException(nameof(exception));
HttpResponseData response = httpRequestData.CreateResponse(HttpStatusCode.InternalServerError);
@@ -101,6 +112,29 @@ public static HttpResponseData CreateErrorResponse(
return response;
}
+ ///
+ /// Creates a bad request response.
+ ///
+ /// The for this response.
+ /// A with a status of Bad Request (400).
+ public static HttpResponseData CreateBadRequestResponse(this HttpRequestData httpRequestData)
+ {
+ return httpRequestData.CreateResponse(HttpStatusCode.BadRequest);
+ }
+
+ ///
+ /// Creates a bad request response with the exception message included.
+ ///
+ /// The for this response.
+ /// The causing the Internal Server Error to be returned.
+ /// A with a status of Bad Request (400) and a response body with the message from .
+ public static HttpResponseData CreateBadRequestResponse(this HttpRequestData httpRequestData, Exception exception)
+ {
+ HttpResponseData response = httpRequestData.CreateResponse(HttpStatusCode.BadRequest);
+ response.WriteString(exception.Message);
+ return response;
+ }
+
///
/// Get a request object from the provide .
///
@@ -108,8 +142,7 @@ public static HttpResponseData CreateErrorResponse(
/// The to be interrogated for the request object.
/// A representing the request object from the request.
/// Thrown if there is an error reading the request object from the request.
- public static Task GetRequestParametersAsync(
- this HttpRequestData httpRequestData) where T : new()
+ public static Task GetRequestParametersAsync(this HttpRequestData httpRequestData) where T : new()
{
return GetRequestParametersAsync(httpRequestData, new Dictionary(), new JsonSerializerOptions());
}
@@ -122,9 +155,7 @@ public static Task GetRequestParametersAsync(
/// Any route values supplied to the Azure Function.
/// A representing the request object from the request.
/// Thrown if there is an error reading the request object from the request.
- public static Task GetRequestParametersAsync(
- this HttpRequestData httpRequestData,
- Dictionary routeValues) where T : new()
+ public static Task GetRequestParametersAsync(this HttpRequestData httpRequestData, Dictionary routeValues) where T : new()
{
return GetRequestParametersAsync(httpRequestData, routeValues, new JsonSerializerOptions());
}