code: def patch_resource(collection, key):
      Upsert" a resource identified by the given key and return the
      appropriate *Response*.
  
      If no resource currently exists at `/<collection>/<key>`, create it
      with *key* as its primary key and return a
      :func:`resource_created_response`.
  
      If a resource *does* exist at `/<collection>/<key>`, update it with
      the data sent in the request and return a :func:`no_content_response`.
  
      Note: HTTP `PATCH` (and, thus, :func:`patch_resource`) is idempotent
  
      :param string collection: a :class:`sandman.model.Model` endpoint
      :param string key: the primary key for the :class:`sandman.model.Model`
      :rtype: :class:`flask.Response`
  
      """
      cls = endpoint_class(collection)
  
      try:
          resource = retrieve_resource(collection, key)
      except InvalidAPIUsage:
          resource = None
  
      _validate(cls, request.method, resource)
  
      if resource is None:
          resource = cls()
          resource.from_dict(get_resource_data(request))
          setattr(resource, resource.primary_key(), key)
          _perform_database_action('add', resource)
          return resource_created_response(resource)
      else:
          return update_resource(resource, request)
docs: Upsert" a resource identified by the given key and return the
      appropriate *Response*.
  
      If no resource currently exists at `/<collection>/<key>`, create it
      with *key* as its primary key and return a
      :func:`resource_created_response`.
  
      If a resource *does* exist at `/<collection>/<key>`, update it with
      the data sent in the request and return a :func:`no_content_response`.
  
      Note: HTTP `PATCH` (and, thus, :func:`patch_resource`) is idempotent
  
      :param string collection: a :class:`sandman.model.Model` endpoint
      :param string key: the primary key for the :class:`sandman.model.Model`
      :rtype: :class:`flask.Response`