Implementing create with POST
Closed this issue · 1 comments
mariofaske commented
Example 4.5 A Java servlet implementation for creating a coffee order
protected void doPost(HttpServletRequest request, HttpServletResponse response) {
try {
Order order = extractOrderFromRequest(request);
if(order == null) {
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
} else {
String internalOrderId = saveOrder(order);
response.setHeader(″Location″, computeLocationHeader(request,
internalOrderId));
response.setStatus(HttpServletResponse.SC_CREATED);
} catch(Exception ex) {
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}
}
mariofaske commented
Implemented the example as accurately as possible