{"id":28660103,"url":"https://github.com/stegano/express-socket.io","last_synced_at":"2025-06-13T10:09:52.362Z","repository":{"id":98532686,"uuid":"408848260","full_name":"stegano/express-socket.io-middleware","owner":"stegano","description":"This middleware allows you to easily convert your existing HTTP REST APIs to websockets","archived":false,"fork":false,"pushed_at":"2021-11-24T15:22:40.000Z","size":255,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-28T13:39:37.748Z","etag":null,"topics":["express","expressjs","socket-io","socketio","websocket"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stegano.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-09-21T14:16:05.000Z","updated_at":"2022-10-18T20:57:09.000Z","dependencies_parsed_at":"2023-06-02T14:45:24.439Z","dependency_job_id":null,"html_url":"https://github.com/stegano/express-socket.io-middleware","commit_stats":{"total_commits":8,"total_committers":1,"mean_commits":8.0,"dds":0.0,"last_synced_commit":"d46a5f39ac9fac2af8da3261390bc534f45b8161"},"previous_names":["stegano/express-socket.io"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/stegano/express-socket.io-middleware","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stegano%2Fexpress-socket.io-middleware","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stegano%2Fexpress-socket.io-middleware/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stegano%2Fexpress-socket.io-middleware/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stegano%2Fexpress-socket.io-middleware/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stegano","download_url":"https://codeload.github.com/stegano/express-socket.io-middleware/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stegano%2Fexpress-socket.io-middleware/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259624744,"owners_count":22886331,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["express","expressjs","socket-io","socketio","websocket"],"created_at":"2025-06-13T10:09:52.026Z","updated_at":"2025-06-13T10:09:52.326Z","avatar_url":"https://github.com/stegano.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Express Socket.io Middleware\n\u003e This middleware allows you to use the existing HTTP REST API as a WebSocket.\n\n## Installation\n\nThe easiest way to install `express-socket.io-middleware` is with [npm](https://www.npmjs.com/package/express-socket.io-middleware).\n\n```bash\nnpm install express-socket.io-middleware\n```\n\nAlternately, download the source.\n\n```bash\ngit clone https://github.com/stegano/express-socket.io-middleware.git\n```\n\n## Example\nThis middleware allows you to process all rest api requests and responses implemented as websockets.\n### Server\n```ts\n...\nconst app = express();\nconst server = http.createServer(app);\nconst io = new Server(server, { \n  path: '/ws',\n});\n\napp\n  .use(socketIoMiddleware(io, 'http://localhost:3000', 'secret!'))\n  .get('/test', (_, res) =\u003e {\n    res.send({message: 'Hello World'})\n  });\n\nserver.listen(3000);\n...\n```\n\n### Clients\n* You can change the event name in configuration. Please check the [Configuration](#configuration) section.\n#### Client With Socket.io\n\u003e Request through websocket and receive a response\n```ts\n// 1) Create and connect socket object\nconst socket = io({\n      path: '/ws',\n      transports: ['websocket']\n    });\n\n// 2) Send request using WebSocket\nsocket.emit('request', {\n  pathanme: '/test',\n  method: 'GET',\n  data: {},\n  params: {}\n});\n\n// 3) Receive response using WebSocket\nsocket.on('response', (data) =\u003e {\n  console.log(data); // `{ request: {...}, response: { ..., data: 'Hello World' }} }`\n});\n```\n\n#### Client With HTTP API and Socket.io\n\u003e Request using REST API and receive response using WebSocket\n```ts\n// 1) Create and connect socket object\nconst socket = io({\n      path: '/ws',\n      transports: ['websocket']\n    });\n\n// 2) Receive auth token via WebSocket\nsocket.on('token', ({token}) =\u003e {\n  // 3) Send REST API request with `authentication` header\n  axios.get('/test', {\n    headers: {\n      authorization: `Bearer ${token}`\n    }\n  })\n});\n\n\nsocket.on('response', (data) =\u003e {\n  // 4) Receive REST API response as WebSocket\n  console.log(data); // `{ request: {...}, response: { ..., data: 'Hello World' }} }`\n});\n```\n\n## Configuration\n```ts\n  /**\n   * Send an error message to the socket\n   * When an unexpected error occurs during internal processing of socketIoMiddleware.\n   */\n  unexpectedErrorMessage?: string\n  /**\n   * This setting can transform the response payload data to be sent to the socket.\n   */\n  transformResponsePayload?: (data: ResponsePayload) =\u003e any\n  /**\n   * This setting can change the socket event name.\n   */\n  eventNames?: {\n    /**\n     * When a socket is connected, it sends a JWT. This token contains authentication information\n     * about the socket to connect to when making an API request.\n     */\n    token?: string\n    /**\n     * The name of the event to request with the websocket.\n     */\n    request?: string\n    /**\n     * The name of the event that will receive a response to information requested by the websocket.\n     */\n    response?: string\n  }\n  __advanced__?: {\n    /**\n     * Whether keepalive is enabled when communicating with the server internally\n     */\n    httpKeepAlive?: boolean\n    /**\n     * Setting up the axios library that is internally communicating with the server\n     * @see https://github.com/axios/axios#request-config\n     */\n    axiosRequestConfig?: AxiosRequestConfig\n  }\n```\n\n## Internal Implementation\nThis middleware internally sends an HTTP request to the web server and sends the received response value to the connected web socket.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstegano%2Fexpress-socket.io","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstegano%2Fexpress-socket.io","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstegano%2Fexpress-socket.io/lists"}