Transports
Ginject supports multiple transports — HTTP for REST APIs and WebSocket for real-time communication. Both use the same processing stages.
Transports
Ginject supports multiple transports, each with its own communication pattern but all sharing the same processing stages (middleware, guard, interceptor, handler, exception filter).
HTTP
HTTP is the standard request-response protocol for building REST APIs.
When to Use HTTP
- Public APIs consumed by web/mobile clients
- Stateless request-response patterns
- REST/CRUD operations
- APIs behind CDNs or load balancers
- Standard API versioning needs
How HTTP Requests Flow
HTTP Controller Structure
Routing Convention
HTTP method tokens:
| Token | HTTP Method | Use Case |
|---|---|---|
READ | GET | Retrieve resource(s) |
CREATE | POST | Create new resource |
UPDATE | PUT | Replace entire resource |
MODIFY | PATCH | Partial update |
DELETE | DELETE | Remove resource |
PREFLIGHT | OPTIONS | CORS preflight |
Path tokens:
| Token | Meaning | Example |
|---|---|---|
BY | Path parameter | READ_BY_ID → GET /:id |
AND | Additional segment | READ_AND_PROFILE → GET /profile |
OF | Sub-resource | READ_OF_COMMENTS → GET /comments |
ANY | Wildcard * | READ_ANY → GET /* |
FILE | File extension | READ_ANY_FILE_HTML → GET /*.html |
VERSION_N | API version | READ_VERSION_2 → GET / (version 2) |
Examples:
Handler Parameter Injection
HTTP handlers receive parameters by type declaration:
Status Codes and Response Format
Responses are automatically serialized:
WebSocket
WebSocket provides persistent, full-duplex bidirectional communication over a single TCP connection.
When to Use WebSocket
- Real-time notifications (push notifications, live updates)
- Chat and messaging applications
- Collaborative features (live editing, shared whiteboards)
- Server-initiated messages to clients
- Low-latency bidirectional streaming
- Presence and activity indicators
How WebSocket Requests Flow
WebSocket Controller Structure
Event Routing Convention
WebSocket methods map to event names (lowercase):
WebSocket Handler Parameter Injection
WebSocket handlers receive:
Note: HTTP-specific types (Body, Query, Header, etc.) are NOT available in WebSocket handlers.
Client Example
Broadcasting to Multiple Connections
WebSocket handlers can broadcast to all connected clients:
Differences from HTTP
| Aspect | HTTP | WebSocket |
|---|---|---|
| Connection lifetime | Per-request | Per-connection |
| Routing | By method + path | By event name |
| Status codes | Yes (200, 404, 500) | No (events only) |
| Headers | Request/response headers | None (persistent connection) |
| Handshake | None | HTTP upgrade → WS connection |
| Broadcasting | Not applicable | Yes, publish to all |
| Parameter types | Body, Query, Param, Header | Payload only |
Summary
Both HTTP and WebSocket use the same pipeline stages:
Choose based on your use case:
- HTTP: REST APIs, stateless, standard web APIs
- WebSocket: Real-time, stateful, bidirectional streaming
Build once with the unified stage model, deploy both.