#Can I integrate both websocket and REST API into one folder (in NestJS Structure)?

1 messages · Page 1 of 1 (latest)

meager heart
#

Hi, I have the following question. Thanks in advance.

For sending realtime notification to frontend, I need websocket server. For this, I can create gateway for 'notification api' using 'nest g resource notification'.

However, I also need REST API for notification (update and list up notifications). For this I need to create REST API for notification api. I can do the same 'nest g resource notification', but choosing REST this time.

Now I have two different APIs for one resource, 'notification'.

Can I use one API directory for notification?

vagrant shale
#

You can create notification.gateway.ts (ws) near notification.controller.ts (rest). Websocket serve ws://hostname and REST serve http://hostname/notifications. What's problem?

meager heart
#

Oh I just tried to create with nest g resource and gave me the attached error. But seems like manaually adding controller to existing websocket api works as you said. Thanks!

vagrant shale
#

nest g resource notification -> Websocket and then nest g controller notification -> REST API create files too

meager heart
#

Thanks, I didn't know there is an option for nest g controller!