Skip to content

Make http status code available#1504

Merged
normj merged 4 commits intoaws:devfrom
kabaluk:make-http-status-code-available
May 5, 2023
Merged

Make http status code available#1504
normj merged 4 commits intoaws:devfrom
kabaluk:make-http-status-code-available

Conversation

@kabaluk
Copy link
Copy Markdown
Contributor

@kabaluk kabaluk commented May 4, 2023

Issue #1468

Made HttpStatusCode available for ease of testing.

Common Usage scenario:
Testing if you got the right Status result from a function returning IHttpResult.
Currently no easy way of checking the actual result.
Exposing the HttpStatusCode solves the below scenario.

public class Functions
{
    [LambdaFunction]
    [HttpApi(LambdaHttpMethod.Get, "/resource/{type}")]
    public IHttpResult GetResponse(string type, ILambdaContext context)
    {
        return type == "good" ?
            HttpResults.Ok() :
            HttpResults.BadRequest();
    }
}

public class HtttpResultsStatusCodeUsage
{
    [Fact]
    public void UsageOfIHttpResultStatusCode()
    {
        var sut = new Functions();

        var result = sut.GetResponse("good", null);

        Assert.Equal(HttpStatusCode.OK, result.StatusCode);

        result = sut.GetResponse("not good", null);

        Assert.Equal(HttpStatusCode.BadRequest, result.StatusCode);
    }
}

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@ashovlin ashovlin requested review from ashovlin and normj May 4, 2023 20:36
Copy link
Copy Markdown
Member

@normj normj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

Copy link
Copy Markdown
Member

@ashovlin ashovlin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! "Source Generator CI" is expected to fail because this is from a fork, but not concerned.

@ashovlin ashovlin changed the base branch from master to dev May 4, 2023 21:15
@chrispaynter
Copy link
Copy Markdown

Nice!

@normj normj merged commit 2a33107 into aws:dev May 5, 2023
@normj
Copy link
Copy Markdown
Member

normj commented May 8, 2023

Version 0.13.3 is out with this PR. Thanks again for the PR!

@kabaluk kabaluk deleted the make-http-status-code-available branch September 3, 2023 16:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants