In this video we're going to get started working on our query service to remember the goal of this service.
We want to have one service that we can make a request to to get a full listing of all the different
posts and their associated comments.
The one request all the data we need to actually implement this thing we're going to give it to different
root handlers one root Handler's going to receive events from our event bus.
Our query service is going to care about events of type posts created and come and created whenever
it sees these events.
It's going to take the data contained inside the event itself and then assemble it all into some very
easy to access data structure.
The second end point that we're going to implement is going to have a handler for watching a GET request
to slash posts anytime so it makes a GET request to that endpoint.
We're going to send back a full listing all posts and related comments.
So let's get start working on our query service.
Right now again I'm going to open up yet another terminal window here's my new window right here.
I'm going to change back into our route blog directory.
That's where all of our services live right now.
And inside there I'll make a new folder we'll call complete query or then change into that directory.
And I'm going to generate a package dot JS on file using NPM minute dash y after I generate that file.
Well then go ahead and install two dependencies.
All we need for this service is express and course the query service itself is not going to actually
emit any events.
And that's why we are not installing axles.
I know ahead of time that the query service is not going to commit any events but if you were working
on this from scratch and if you were unsure about whether or not this thing was going to be met any
events you would go ahead and install axles until you were sure that OK.
I don't actually need to treatment and events and then you can remove that dependency.
So I'll go ahead and do that installation I'll then go back over to my editor and I should see that
new query directory so let's start to build this Express application out inside of that directory.
I'll make a new file called index dot J.S. and then at the top let's go ahead.
We're going to require an express body parser and that course module as well will get Express will get
body parser
and I'll get yours I'll then create my new express app and I will wire up the body of parser
and I will wire up cause OK so it looks good now we're going to put together our two root handlers remember
the two that we want are for a get to slash post and they post to slash events we'll do app dot get
slash post and then put it in our rec and rez.
And right now I'll just see that empty and then the next one will be app dot post to slash events.
So this is of course the end point that is going to receive events from our event bus then finally at
the very bottom.
Let's go ahead and set up that app.
Listen call it will do an app listen and remember.
At present we are using a couple of different ports.
We've got ports or thousand 1001 and 4000 to I think now just 4000 of 4000 one.
This one will be at 4000 and to open in our callback inside of here we'll do a console log listening
on 4000 to before we start to worry about any implementation here just yet.
Let's make sure we can actually run this project it's going to save this file.
I'll go back over to a package that Jason and we'll set up a startup script that's what we forgot on
dependencies we've got to get Node 1.
We'll go and install that really quickly as well.
Rebecca my terminal will do an MP install node on
and then once that is installed we can update that start script though start with the node man index
that J.S. let's just run this project really quickly to make sure we don't have any typos or anything
like that.
So at my terminal in the window that is running our query service we'll do an NPM start and there we
go listing on 4000 to.
Well now that we've got all this boilerplate put together we can start worrying about the actual implementation
of the post events end point and get post as well.
We'll do a quick break first and then start to worry about those two end points in just a moment.