Skip to content

Instantly share code, notes, and snippets.

@theawesomenayak
Created October 24, 2020 12:09
Show Gist options
  • Save theawesomenayak/eb0a804afa955087aecf32b6e990f997 to your computer and use it in GitHub Desktop.
Save theawesomenayak/eb0a804afa955087aecf32b6e990f997 to your computer and use it in GitHub Desktop.
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