The video demonstrates how to implement and test HTTP keepalive functionality in a NestJS project. The developer creates Upstream and Demo controllers, simulates network requests using Postman, and highlights performance improvements by observing socket reuse and reduced latency.
Length 12:37
Captions English (Generated), Spanish (Auto-translated), French (Auto-translated), Korean (Auto-translated), Portuguese (Auto-translated), Vietnamese (Auto-translated) #http #keepalive #nestjs #typescript #web development #networking #postman #api #backend #socket
0:00 All right, so to test out our HTTP functionality in 0:03 this 0:04 project, I'm gonna create a new demo directory 0:08 where we can create a couple of demo controllers. 0:11 So like I said, this application is gonna act as both the client 0:14 and server. 0:15 We're gonna make network requests to it, which is perfectly fine and 0:18 reasonable to do. That will demonstrate all of our HTTP 0:22 functionality. 0:24 So inside of demo, I wanna create two controllers. 0:27 I wanna create a demo controller, which is where we're gonna send requests 0:31 to to start our demonstrations, and then I'm 0:35 gonna create a upstream controller, which is 0:39 gonna receive the requests from the demo controller using 0:43 our HTTP service. 0:45 So let's start off with actually implementing the upstream 0:49 controller so that we have something to call. 0:52 And so for this, I'm gonna create the @Controller 0:55 decorator and give it 0:58 a prefix of upstream. So we'll export 1:01 class UpstreamController and the first method I'm gonna 1:05 create is a get method 1:08 and I'll give this a title of unstable 1:12 because later on we're actually gonna demonstrate our retry 1:16 functionality through this very same method, but this is also gonna work 1:20 for showing off our keepalive connection and this is because 1:24 we can actually take in a query parameter here using the @Query 1:27 decorator 1:29 that takes in any query parameters. 1:31 So I wanna have a fail rate query parameter 1:35 that we're gonna initialize to zero point six, which is gonna be the rate of 1:38 failures for this method to simulate failures and 1:42 trigger our retry mechanism. 1:44 In our case for our keepalive demo, we will pass a fail rate of zero, 1:49 so this never fails, but this is gonna allow us to test out both 1:52 retries and keepalive. So I'll also create 1:56 a rate from this fail rate
The rest of the transcript is for members.
Sign in