lambadaframework
lambadaframework copied to clipboard
Form and Post data support along with DefaultValue support
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.
I'll be looking into it as soon as possible, thanks
Thanks
Updated code in PR with latest from master. (And tested.)
- 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.)
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.
Ping.