code: def api_stop(server_state):
      
      api_srv = server_state['api']
  
      if api_srv is not None:
          log.info("Shutting down API")
          api_srv.stop_server()
          api_srv.join()
          log.info("API server joined")
      else:
          log.info("API already joined")
  
      server_state['api'] = None
docs: Stop the global API server thread