Overview
Apinizer WebSocket proxy works with exactly the same logic as HTTP APIs. You can route both HTTP and WebSocket requests through the same API Proxy.
Basic Concepts
- Backend URL: The only required configuration (e.g.,
http://backend:9090/ws/api) - Relative Path: Same as HTTP APIs (e.g.,
/websocket/*, /chat/*) - Protocol Conversion:
http:// → ws://, https:// → wss://
How It Works
Unified Path Resolve Process:
Incoming Request: ws://host/api/websocket/rooms/123?user=john
├─ API Proxy Path: /api/websocket/*
├─ Backend URL: http://localhost:9090/ws/chat
├─ Protocol Conversion: ws://localhost:9090/ws/chat
├─ Remaining Path: rooms/123
└─ Final URL: ws://localhost:9090/ws/chat/rooms/123?user=john
CODE
Path Resolve Steps
- Query Separation: Query parameters are separated from request path
- Path Normalization: Wildcard markers (
*) are cleaned - Remaining Path: API proxy path is removed
- Protocol Conversion: HTTP → WebSocket
- URL Combination: Backend URL + Remaining Path + Query
Practical Examples
Example 1: HTTP and WebSocket Combined
API Proxy: /api/v1/*
Backend URL: http://localhost:8080/service
HTTP Request:
POST /api/v1/users → http://localhost:8080/service/users
WebSocket Request:
ws://host/api/v1/chat → ws://localhost:8080/service/chat
--------------------------------------------------------
Example 2: Secure Connection
API Proxy: /secure/*
Backend URL: https://api.example.com/ws
WebSocket Request:
ws://host/secure/data → wss://api.example.com/ws/data
--------------------------------------------------------
Example 3: Chat Application
API Proxy: /chat/*
Backend URL: http://chat-service:9090/websocket
WebSocket Request:
ws://host/chat/room/123 → ws://chat-service:9090/websocket/room/123
CODE
Frequently Asked Questions
Q: Can the same API Proxy support both HTTP and WebSocket?
A: Yes! Both protocols work under the same relative path.
Q: Which protocol should I use in Backend URL?
A: Use HTTP or HTTPS. The system automatically converts to WS/WSS.
Q: Are query parameters preserved?
A: Yes, all query parameters are passed to the backend as-is.
Q: How can I make my existing HTTP APIs WebSocket-enabled?
A: Just enable WebSocket support from Environment Settings.