Skip to content

Commit a4d8f2a

Browse files
committed
Supporting empty payloads for POST, PATCH and PUT
1 parent a45a144 commit a4d8f2a

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

plugins/magic.lambda.http/magic.lambda.http/services/MagicHttp.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -391,10 +391,6 @@ static object GetRequestContentContent(
391391
// Checking if caller supplied a [payload] value or not, alternatives are structured lambda object.
392392
if (payloadNode.Value == null)
393393
{
394-
// Verifying user supplied some sort of structured lambda object type of content.
395-
if (!payloadNode.Children.Any())
396-
throw new HyperlambdaException($"No [payload] value or children supplied to [{input.Name}]");
397-
398394
// Figuring out Content-Type of request payload to make sure we correctly transform into the specified value.
399395
var contentType = headers.ContainsKey("Content-Type") ?
400396
ContentType.Parse(headers["Content-Type"]) :
@@ -409,8 +405,7 @@ static object GetRequestContentContent(
409405
else
410406
{
411407
// [payload] contains a value object of some sort.
412-
return payloadNode?.GetEx<object>() ??
413-
throw new HyperlambdaException($"No [payload] value supplied to [{input.Name}]");
408+
return payloadNode?.GetEx<object>();
414409
}
415410
}
416411

@@ -422,7 +417,7 @@ async Task<object> GetRequestFileContentAsync(Node input)
422417
// If no [content] was given we check if caller supplied a [filename] argument.
423418
var filename = input.Children.FirstOrDefault(x => x.Name == "filename")?.GetEx<string>();
424419
if (filename == null)
425-
throw new HyperlambdaException($"No [payload] or [filename] argument supplied to [{input.Name}]");
420+
return "";
426421

427422
// Caller supplied a [filename] argument, hence using it as a stream content object.
428423
if (await _fileService.ExistsAsync(_rootResolver.AbsolutePath(filename)))

plugins/magic.lambda.http/magic.lambda.http/services/helpers/RequestTransformers.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ internal static object TransformToJson(
2929
Node payloadNode,
3030
string slotName)
3131
{
32+
// Short circuiting if we have no nodes.
33+
if (!payloadNode.Children.Any())
34+
return "";
35+
3236
/*
3337
* Automatically [unwrap]'ing all nodes, since there are no reasons why you'd want
3438
* to pass in an expression as JSON token to an endpoint.

0 commit comments

Comments
 (0)