lambadaframework icon indicating copy to clipboard operation
lambadaframework copied to clipboard

Form and Post data support along with DefaultValue support

Open arranubels opened this issue 8 years ago • 6 comments

Hi,

I have made a couple improvements to the form data and post data changes, taking into consideration recent updates to master.

With this change the following methods work:

Objects

    public static class Input {
        public String value;

        public Input(String value) {
            this.value = value;
        }

        public Input() {
        }
    }

    @POST
    @Path("test/test1")
    @Produces(MediaType.APPLICATION_JSON)
    @Consumes(MediaType.APPLICATION_JSON)
    public Response test1(Input value) {

        logger.debug("Request got");
        return Response.status(201)
                .entity(value)
                .build();
    }

Request text

{ "value": "asdfasdf" }

Query:

++ curl -X POST -d @testfiles/object.txt https://xxxx.execute-api.eu-west-1.amazonaws.com/production/test/test1 --header 'Content-Type: APPLICATION/JSON'
+ echo '{"value":"asdfasdf"}'

Json text

    @POST
    @Path("test/test2")
    @Produces(MediaType.APPLICATION_JSON)
    @Consumes(MediaType.APPLICATION_JSON)
    public Response test2(String value) {

        logger.debug("Request got");
        return Response.status(201)
                .entity(value)
                .build();
    }

Request text:

"asdfasdf"

Query:

++ curl -X POST -d @testfiles/jsonstring.txt https://xxx.execute-api.eu-west-1.amazonaws.com/production/test/test2 --header 'Content-Type: APPLICATION/JSON'
+ echo '"asdfasdf"'
"asdfasdf"

Form param

    @POST
    @Path("test/test3")
    @Produces(MediaType.APPLICATION_JSON)
    @Consumes(MediaType.APPLICATION_JSON)
    public Response test3(@FormParam("value") String value) {

        logger.debug("Request got");
        return Response.status(201)
                .entity(value)
                .build();
    }

This can be used multiple ways:

Way 1

"value=asdfasdf"

Query

++ curl -X POST -d @testfiles/jsonformenc.txt https://xxxx.execute-api.eu-west-1.amazonaws.com/production/test/test3 --header 'Content-Type: APPLICATION/JSON'
+ echo '"asdfasdf"'
"asdfasdf"

Way 2

value=asdfasdf

Query

++ curl -X POST -d @testfiles/formenc.txt https://xxx.execute-api.eu-west-1.amazonaws.com/production/test/test3 --header 'Content-Type: APPLICATION/JSON'
+ echo '"asdfasdf"'
"asdfasdf"

Multiple values

    @POST
    @Path("test/test4")
    @Produces(MediaType.APPLICATION_JSON)
    @Consumes(MediaType.APPLICATION_JSON)
    public Response test4(@FormParam("value") List<String> value) {

        logger.debug("Request got");
        return Response.status(201)
                .entity(value)
                .build();
    }

Request text:

value=asdfasdf&value=12312312

Query

++ curl -X POST -d @testfiles/arrayformenc.txt https://xxxx.execute-api.eu-west-1.amazonaws.com/production/test/test4 --header 'Content-Type: APPLICATION/JSON'
+ echo '["asdfasdf","12312312"]'
["asdfasdf","12312312"]

Note

Please note: I don't do anything with @Produces, other @Consumes could be supported easily with some Api Gateway changes.

Please let me know if you need me to change anything.

arranubels avatar Jul 07 '16 04:07 arranubels

I'll be looking into it as soon as possible, thanks

cagataygurturk avatar Jul 09 '16 08:07 cagataygurturk

Thanks

arran4 avatar Jul 13 '16 01:07 arran4

Updated code in PR with latest from master. (And tested.)

arranubels avatar Jul 14 '16 05:07 arranubels

  • TravisCI is no longer depending on AWS credentials. So for pull requests tests should pass also. Can you check? There is one failing tests now.
  • Why jackson-databind is not provided dependency? That package is already included in Lambda runtime, there is no need to add it again to our JAR. (Lambda functions has a maximum size of 50 MB and every byte saved in dependencies is more space for user code.)

cagataygurturk avatar Jul 14 '16 06:07 cagataygurturk

Tests now working, it was a type cast issue. I also included a log4j file which will be included only for test and modified the test class path to the default maven one so it didn't have to be explicitly mentioned. Happy to revert if there was a reason for it. (I couldn't see.)

I reverted it back to being a provided dependency, sorry I didn't know why it was provided.

arranubels avatar Aug 01 '16 05:08 arranubels

Ping.

arran4 avatar Sep 29 '16 00:09 arran4