2.1.17 • Published 1 month ago
express-yaschema-ws-api-handler v2.1.17
express-yaschema-ws-api-handler
Express support for handling WebSocket APIs declared using yaschema-ws-api.
Basic Example
// API schema and metadata
// You'll typically define this in a separate package shared by your server and clients
export const stream = makeWsApi({
routeType: 'stream',
url: '/stream',
requests: {
ping: schema.object({ echo: schema.string().allowEmptyString().optional() }).optional(),
hello: schema.any().optional()
},
responses: {
pong: schema.object({
body: schema.string()
}),
hello: schema.object({
body: schema.string()
})
}
});
import expressWS, { WithWebsocketMethod } from 'express-ws';
…
// Add WebSocket support to Express
expressWs(app);
const appWithWs = app as typeof app & WithWebsocketMethod;
registerWsApiHandler(
appWithWs,
api.stream,
{},
{
ping: async ({ input, output }) => output.pong({ body: `PONG${(input?.echo?.length ?? 0) > 0 ? ' ' : ''}${input?.echo ?? ''}` }),
hello: async ({ output }) => output.hello({ body: 'world' })
}
)
The options object passed to registerWsApiHandler
lets you override the validation mode and/or specify middleware.
Thanks
Thanks for checking it out. Feel free to create issues or otherwise provide feedback.
Be sure to check out our other TypeScript OSS projects as well.
2.1.17
1 month ago
2.1.16
2 months ago
2.1.15
2 months ago
2.1.14
3 months ago
2.1.13
3 months ago
2.1.12
4 months ago
2.1.10
4 months ago
2.1.11
4 months ago
2.1.9
4 months ago
2.1.7
4 months ago
2.1.6
4 months ago
2.1.5
4 months ago
2.1.4
5 months ago
2.1.3
7 months ago
2.1.2
11 months ago
2.1.1
11 months ago
2.1.0
11 months ago
1.3.1
1 year ago
1.3.0
1 year ago
2.0.0
1 year ago
1.2.0
1 year ago
1.1.2
1 year ago
1.1.1
1 year ago
1.1.0
1 year ago
1.0.0
1 year ago
0.0.0-alpha.10
1 year ago
0.0.0-alpha.9
1 year ago
0.0.0-alpha.8
1 year ago
0.0.0-alpha.7
1 year ago
0.0.0-alpha.6
1 year ago
0.0.0-alpha.5
1 year ago
0.0.0-alpha.4
1 year ago
0.0.0-alpha.3
1 year ago
0.0.0-alpha.2
1 year ago
0.0.0-alpha.1
1 year ago
0.0.0-alpha.0
1 year ago