code: def put_resource(collection, key):
      
      resource = retrieve_resource(collection, key)
  
      _validate(endpoint_class(collection), request.method, resource)
  
      resource.replace(get_resource_data(request))
      try:
          _perform_database_action('add', resource)
      except IntegrityError as exception:
          raise InvalidAPIUsage(422, FORWARDED_EXCEPTION_MESSAGE.format(
              exception))
      return no_content_response()
docs: Replace the resource identified by the given key and return the
      appropriate response.
  
      :param string collection: a :class:`sandman.model.Model` endpoint
      :rtype: :class:`flask.Response`