Now regarding the routes,
I'll add a new folder to dos dot routes dot JS.
And in this folder, as always,
we start by importing express like this,
and we get the router by calling
express dot router like that.
And we of course then export this
to make it available outside of this file.
And then with that done, we can register our routes.
And here for the moment, I need two routes,
a get and a post route because these are the two controller
actions on which we work thus far.
And speaking of that, of course,
we also need the to do's controller here,
which we get by requiring controllers, to do's controller.
Now I do again expect that these routes are loaded such that
a certain prefix, slash to dos to be precise,
is added automatically in app JS.
So therefore here I can handle
just get slash and then point at to do's controller,
get all to dos,
and here also have slash,
but with a different request method,
and they offer as you learn,
it's a totally different route
and a totally different end point.
And here I will then trigger to do's controller, add to do.
Now we need to load these routes in app JS.
And for this here,
I'll add my to do's routes...
...by requiring...
dot slash routes to dos routes.
And I want to register them here, where I will use app use.
And now add to that prefix I was talking about slash to dos,
which will automatically be added in front of all the paths
we are handling here instead of to do's routes,
but which will be stripped
once a request reaches this file here.
And then here, I want to point at to do's routes.
So all requests where the path starts with slash to dos
will be forwarded to my to do's routes,
and then it will be handled there.
Now there is one important middleware
which we'll have to add,
which we didn't add before in the last API.
And that's adjacent body parser middleware because of course
in to do's controller, when we add a to do,
I'm extracting data from the incoming request body.
And for this to succeed,
we need a middleware that actually reads that incoming
request body, and makes it available through JavaScript, on
this body object, on the request object.
And of course,
this is also something we already solved before in the
course, but I want to emphasize it again here.
We now need to use a new middleware and that's the express
dot J son middleware. Where to J son method,
which will then yield the actual middleware,
which will scan all incoming requests for their content
type. And if it's J son, it will parse the request
body as J son and expose it under this rec dot body field so
that we can work with it in our other middleware functions,
and in our controller action, stale four.
And then with that, we should be able to get that data.
Now with all that done, we added these two routes,
we added the controllers, and the model, and the middleware.
This should be working, but how can we now test this.