04 - authtestcontroller.js
In this module, we'll add a new controller that requires a user token for all requests.
Overview
We are going to add a number of endpoints/routes in this controller. We will give you all of this code and will be analyzing it in the future.
Code
Create an authtestcontroller.js
file inside of the controllers
folder, then add the following code:
Short Analysis
Although there are nuances that we'll discuss, the functions should seem somewhat familiar to you based on our previous server functions. Here is a quick explanation for each of them:
Function
Purpose
/getall
Finds all items in the table with the user id
in the token
/:id
Finds a single item in the the table. Uses both the id
from the url (primary key) and the userid
from the token (foreign key).
/create
Adds an item to the table with the userid
from the token.
Up until now, we've only done GET
and POST
requests. A full CRUD (Create Read Update Delete) app lets you update and delete stuff, however, so we need to add some DELETE
and UPDATE
functionality. Let's talk a little more about each and set up a route for each before we start testing.
Last updated