WebSocket API Proxy Creation
Overview
Apinizer WebSocket proxy works exactly the same logic as HTTP APIs. You can route both HTTP and WebSocket requests through the same API Proxy.
Basic Concepts
The only required configuration. Specifies the address of your backend WebSocket service.
Example: http://backend:9090/ws/api
Works the same logic as HTTP APIs. You can perform flexible routing using wildcards.
Examples: /websocket/*, /chat/*
The system automatically performs protocol conversion:
http://→ws://https://→wss://
How It Works?
Unified Path Resolve Process
Path Resolve Example
The following example shows how a WebSocket request is processed:
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
Path Resolve Steps
Processing of WebSocket requests goes through the following steps:
Query parameters are separated from the request path.
Wildcard signs (*) are cleaned.
API proxy path is extracted and the remaining path is determined.
HTTP → WebSocket protocol conversion is performed (http:// → ws://, https:// → wss://).
Final URL is created by combining Backend URL + Remaining Path + Query parameters.
Practical Examples
Routing both HTTP and WebSocket requests through the same API Proxy:
Configuration:
- API Proxy:
/api/v1/* - Backend URL:
http://localhost:8080/service
Example Requests:
- HTTP:
POST /api/v1/users→http://localhost:8080/service/users - WebSocket:
ws://host/api/v1/chat→ws://localhost:8080/service/chat
Secure WebSocket connection with HTTPS backend:
Configuration:
- API Proxy:
/secure/* - Backend URL:
https://api.example.com/ws
Example Request:
- WebSocket:
ws://host/secure/data→wss://api.example.com/ws/data
When HTTPS backend is used, it is automatically converted to WSS (WebSocket Secure) protocol.
WebSocket proxy example for chat application:
Configuration:
- API Proxy:
/chat/* - Backend URL:
http://chat-service:9090/websocket
Example Request:
- WebSocket:
ws://host/chat/room/123→ws://chat-service:9090/websocket/room/123
Frequently Asked Questions
Can the same API Proxy support both HTTP and WebSocket?
Yes! Both protocols work under the same relative path.
You can route both HTTP and WebSocket requests with the same API Proxy configuration. The system automatically detects the protocol type of the incoming request and processes it appropriately.
Which protocol should I use in Backend URL?
Use HTTP or HTTPS. The system automatically converts to WS/WSS.
You can use http:// or https:// protocol in Backend URL. Apinizer automatically performs conversion for WebSocket requests:
http://→ws://https://→wss://
Are query parameters preserved?
Yes, all query parameters are transferred to the backend as-is.
Query parameters (?param=value) in WebSocket requests are preserved and transferred to the backend. For example:
ws://host/api/chat/room/123?user=john&token=abc
This request is routed to the backend with query parameters.
How can I make my existing HTTP APIs WebSocket-enabled?
Go to the settings of the environment that the API Proxy is connected to.
Enable WebSocket support from environment settings.
Deploy the changes. Your existing HTTP API Proxy will now also support WebSocket requests.
No additional configuration is required for your existing HTTP API Proxies. You just need to enable WebSocket support from environment settings.