1 00:00:01,190 --> 00:00:06,250 In this video we're going to get started working on our query service to remember the goal of this service. 2 00:00:06,290 --> 00:00:11,000 We want to have one service that we can make a request to to get a full listing of all the different 3 00:00:11,000 --> 00:00:13,270 posts and their associated comments. 4 00:00:13,310 --> 00:00:18,110 The one request all the data we need to actually implement this thing we're going to give it to different 5 00:00:18,110 --> 00:00:23,200 root handlers one root Handler's going to receive events from our event bus. 6 00:00:23,210 --> 00:00:28,670 Our query service is going to care about events of type posts created and come and created whenever 7 00:00:28,670 --> 00:00:30,120 it sees these events. 8 00:00:30,140 --> 00:00:34,670 It's going to take the data contained inside the event itself and then assemble it all into some very 9 00:00:34,670 --> 00:00:37,250 easy to access data structure. 10 00:00:37,280 --> 00:00:42,470 The second end point that we're going to implement is going to have a handler for watching a GET request 11 00:00:42,470 --> 00:00:46,260 to slash posts anytime so it makes a GET request to that endpoint. 12 00:00:46,310 --> 00:00:50,140 We're going to send back a full listing all posts and related comments. 13 00:00:50,280 --> 00:00:52,120 So let's get start working on our query service. 14 00:00:52,130 --> 00:00:59,610 Right now again I'm going to open up yet another terminal window here's my new window right here. 15 00:00:59,730 --> 00:01:02,620 I'm going to change back into our route blog directory. 16 00:01:02,620 --> 00:01:05,180 That's where all of our services live right now. 17 00:01:05,180 --> 00:01:12,700 And inside there I'll make a new folder we'll call complete query or then change into that directory. 18 00:01:12,700 --> 00:01:20,460 And I'm going to generate a package dot JS on file using NPM minute dash y after I generate that file. 19 00:01:20,470 --> 00:01:23,590 Well then go ahead and install two dependencies. 20 00:01:23,590 --> 00:01:29,340 All we need for this service is express and course the query service itself is not going to actually 21 00:01:29,360 --> 00:01:30,660 emit any events. 22 00:01:30,790 --> 00:01:33,630 And that's why we are not installing axles. 23 00:01:33,640 --> 00:01:37,840 I know ahead of time that the query service is not going to commit any events but if you were working 24 00:01:37,840 --> 00:01:41,650 on this from scratch and if you were unsure about whether or not this thing was going to be met any 25 00:01:41,650 --> 00:01:45,810 events you would go ahead and install axles until you were sure that OK. 26 00:01:45,820 --> 00:01:50,830 I don't actually need to treatment and events and then you can remove that dependency. 27 00:01:50,920 --> 00:01:57,760 So I'll go ahead and do that installation I'll then go back over to my editor and I should see that 28 00:01:57,760 --> 00:02:04,700 new query directory so let's start to build this Express application out inside of that directory. 29 00:02:04,710 --> 00:02:10,120 I'll make a new file called index dot J.S. and then at the top let's go ahead. 30 00:02:10,160 --> 00:02:19,760 We're going to require an express body parser and that course module as well will get Express will get 31 00:02:19,760 --> 00:02:20,450 body parser 32 00:02:23,830 --> 00:02:33,180 and I'll get yours I'll then create my new express app and I will wire up the body of parser 33 00:02:36,900 --> 00:02:45,370 and I will wire up cause OK so it looks good now we're going to put together our two root handlers remember 34 00:02:45,440 --> 00:02:52,390 the two that we want are for a get to slash post and they post to slash events we'll do app dot get 35 00:02:52,450 --> 00:02:58,370 slash post and then put it in our rec and rez. 36 00:02:58,490 --> 00:03:04,480 And right now I'll just see that empty and then the next one will be app dot post to slash events. 37 00:03:04,480 --> 00:03:10,570 So this is of course the end point that is going to receive events from our event bus then finally at 38 00:03:10,570 --> 00:03:11,230 the very bottom. 39 00:03:11,260 --> 00:03:12,500 Let's go ahead and set up that app. 40 00:03:12,510 --> 00:03:16,060 Listen call it will do an app listen and remember. 41 00:03:16,060 --> 00:03:18,740 At present we are using a couple of different ports. 42 00:03:18,820 --> 00:03:25,830 We've got ports or thousand 1001 and 4000 to I think now just 4000 of 4000 one. 43 00:03:25,900 --> 00:03:36,050 This one will be at 4000 and to open in our callback inside of here we'll do a console log listening 44 00:03:36,080 --> 00:03:41,590 on 4000 to before we start to worry about any implementation here just yet. 45 00:03:41,590 --> 00:03:45,580 Let's make sure we can actually run this project it's going to save this file. 46 00:03:45,580 --> 00:03:51,520 I'll go back over to a package that Jason and we'll set up a startup script that's what we forgot on 47 00:03:51,520 --> 00:03:53,350 dependencies we've got to get Node 1. 48 00:03:53,520 --> 00:03:55,870 We'll go and install that really quickly as well. 49 00:03:55,950 --> 00:03:59,990 Rebecca my terminal will do an MP install node on 50 00:04:04,030 --> 00:04:12,720 and then once that is installed we can update that start script though start with the node man index 51 00:04:12,990 --> 00:04:19,800 that J.S. let's just run this project really quickly to make sure we don't have any typos or anything 52 00:04:19,800 --> 00:04:20,790 like that. 53 00:04:20,850 --> 00:04:27,700 So at my terminal in the window that is running our query service we'll do an NPM start and there we 54 00:04:27,700 --> 00:04:30,840 go listing on 4000 to. 55 00:04:31,080 --> 00:04:34,950 Well now that we've got all this boilerplate put together we can start worrying about the actual implementation 56 00:04:35,010 --> 00:04:38,510 of the post events end point and get post as well. 57 00:04:38,580 --> 00:04:41,840 We'll do a quick break first and then start to worry about those two end points in just a moment.