code: def request(
      method: str,
      port: Optional[int],
      api: str,
      data: Any = None,
      prefix: Optional[str] = None,
  ) -> Any:
      if port is None:
          raise RuntimeError("Experiment is not running")
  
      url_parts = [
          f"http://localhost:{port}",
          prefix,
          "api/v1/nni",
          api,
      ]
      url = "/".join(part.strip("/") for part in url_parts if part)
  
      if data is None:
          resp = requests.request(method, url, timeout=timeout)
      else:
          resp = requests.request(
              method, url, json=data, timeout=timeout
          )
  
      if not resp.ok:
          _logger.error(
              "rest request %s %s failed: %s %s",
              method.upper(),
              url,
              resp.status_code,
              resp.text,
          )
      resp.raise_for_status()
  
      if method.lower() in ["get", "post"] and len(resp.content) > 0:
          return resp.json()
  
file_path: nni/nni/experiment/rest.py
imports: import logging
  from typing import Any, Optional
  import requests
label_desc: Use image node_id 1 for calling a global function with example usage: request(method, port, api, data, prefix) and returns: resp