API Connect

API Connect

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.

 View Only

Unable to Establish WebSocket Connection from IBM API Connect to FastAPI WebSocket Service

  • 1.  Unable to Establish WebSocket Connection from IBM API Connect to FastAPI WebSocket Service

    Posted 2 days ago

    Hello IBM Community,

    I am trying to connect a WebSocket running on my server to IBM API Connect using the websocket-upgrade policy, but I'm unable to establish the connection.

    My Setup:

    • FastAPI WebSocket Service running at: wss://<my-server-ip>:8000/ws

    • Started using: uvicorn app:app --reload --host 0.0.0.0 --port 8000 \
      --ssl-keyfile=./key.pem --ssl-certfile=./cert.pem

    • FastAPI Code:
      Handles /ws for WebSocket, /create-customer to add customer data, and /customers to retrieve customer list.

    APIC Proxy Configuration:

    • Using DataPower API Gateway

    • Added websocket-upgrade policy in the assembly

    • target-url property set to: wss://<my-server-ip>:8000/ws

    • Schemes include both wss and https

    • Configuration : 
      swagger: '2.0'
      info:
        title: ws
        x-ibm-name: ws
        version: 1.0.0
      x-ibm-configuration:
        cors:
          enabled: false
        gateway: datapower-api-gateway
        type: rest
        phase: realized
        enforced: true
        testable: true
        assembly:
          execute:
            - websocket-upgrade:
                request-assembly:
                  execute: []
                  catch:
                    - execute: []
                      otherwise: []
                response-assembly:
                  execute: []
                  catch:
                    - execute: []
                      otherwise: []
                header-control:
                  type: blocklist
                  values: []
                parameter-control:
                  type: allowlist
                  values: []
                version: 2.0.0
                title: websocket-upgrade
                timeout: 60
                target-url: $(target-url)
                inject-proxy-headers: true
        properties:
          target-url:
            description: The URL of the target service
            encoded: false
            value: wss://<my-server-ip>:8000/ws
        activity-log:
          enabled: true
          success-content: activity
          error-content: payload
      basePath: /ws
      paths:
        /data:
          get:
            responses:
              '200':
                description: success
                schema:
                  type: string
      schemes:
        - wss
        - https

    Issue:
    When I try to establish the WebSocket connection from the APIC proxy, the connection fails (even though a direct connection to the FastAPI endpoint works fine).

    Question:

    • Is there any additional configuration required in APIC to successfully connect to a self‑hosted WebSocket endpoint?

    • Do I need any special TLS or network configuration to allow the APIC gateway to connect to my local/private server IP?

    Any guidance, configuration example, or troubleshooting steps will be greatly appreciated.



    ------------------------------
    Mounika Nayikoti
    ------------------------------