Created
October 24, 2020 12:09
-
-
Save theawesomenayak/eb0a804afa955087aecf32b6e990f997 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try { | |
final String httpMethod = input.getHttpMethod(); | |
if ("GET".equalsIgnoreCase(httpMethod)) { | |
final List<Pet> pets = DependencyModule.PET_STORE_CLIENT.read(); | |
final String result = DependencyModule.OBJECT_MAPPER.writeValueAsString(pets); | |
return response.withStatusCode(200).withBody(result); | |
} else { | |
final Pet pet = DependencyModule.OBJECT_MAPPER.readValue(input.getBody(), Pet.class); | |
final String id = DependencyModule.PET_STORE_CLIENT.write(pet); | |
return response.withStatusCode(200).withBody(id); | |
} | |
} catch (final IOException e) { | |
return response.withStatusCode(500).withBody("{}"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment