Refactored the GET and PUT endpoints so they use the same code.