Posts

Showing posts with the label nestjs

Guide to integrating NextJS with gRPC and NestJS via HTTP/2

Image
Introduction gRPC is a high-performance RPC (Remote Procedure Call) framework developed by Google, using Protocol Buffers (protobuf) as the interface definition language and data serialization format. Unlike traditional REST which uses text (JSON), gRPC transmits data in binary format to optimize payload size and processing speed. In particular, gRPC operates based on HTTP/2, providing outstanding advantages such as: Multi-plexing (sending multiple concurrent requests over a single connection), Header Compression, and Server Push, helping to reduce latency and increase bandwidth for microservices systems. In this article, I will use NextJS for the frontend and act as a BFF (Backend For Frontend) as a proxy server to aggregate information and communicate via HTTP/2 gRPC with the NestJS server. Our connection will be as follows: Frontend connects to NextJS proxy server using restful api HTTP/1.1, NextJS connects to NestJS using gRPC via HTTP/2, we need a NextJS middleware to handle it, n...

Connecting NextJS with NestJS via SocketIO

Image
Introduction SocketIO is a powerful library that enables bidirectional, real-time, event-based communication between the server and the browser. The key advantages include: Low Latency: Instant data transmission instead of having to send continuous requests. Reliability: Automatic reconnection on connection loss and fallback support to HTTP long-polling if WebSocket is unavailable. Broadcasting: Easily send data to one or multiple clients simultaneously. In this article, I will guide you on using NextJS and NestJS to communicate with each other via SocketIO, simulating a chatbot app and the AI Agent's workflow. Detail On NestJS project you need to install these packages: yarn add @nestjs/websockets @nestjs/platform-socket.io socket.io Create the controller/conversations.controller.ts file returning the conversation list as follows: import { Controller, Get } from "@nestjs/common" ; @ Controller ( "conversations" ) export class ConversationsController {...