- [Instructor] So far in this course,
we have set up some basic routes using the HTTP methods
get, post, put, and delete.
We've sent data to the client,
but it's been in messages that we've hard-coded
to simply illustrate how to get our endpoints
up and running.
In this video,
we want to take our mock data
and serve it to our client via a get.
This is something that you will do time and time again,
as you build endpoints with express,
we're going to start in our code editor
and then test with postman and the browser.
In our index JS file,
let's take a look at our get route.
We're going to go ahead and clear out the response.send
that we have here and make some changes.
Typically, when you're working with an application
that is using node and express,
you are likely hooking into a database as well.
This is where you be querying and fetching existing data.
For the scope of this course,
we are simply focusing on express,
so we will just briefly touch on this topic.
Inside our get, the first thing we usually do
is get data from a database
and then set up any necessary error handling at this time.
But for this course,
we're going to use the mock data that we already imported
to send to our client.
In order to do that,
we will use the response and then apply the method json
in order to send data to the client in json format.
In order to set this up,
we'll just simply need to pass our data to the json method.
All right, now make sure you save.
That's very important.
And then now we're going to head to postman
to test our get.
In postman, let's open a new tab.
We see the default is get,
so we don't need to make a change there.
We just need to enter a local host 3000 in the URL field.
All right, once we have that, we can now hit send,
and you should see the response mock data down in the body.
Pretty cool.
Now let's see what it looks like in the browser.
If you're not already on local host 3000,
go ahead and head there.
I still have this from our last video,
so I'm simply just going to refresh.
And now we see that we are getting that same mock data here
on the client side or in the browser.
It's identical to what we were seeing in postman.
Great job, you've just served up data using get.