CRUD Again
Learning Objectives
We are building a CRUD API. CRUD stands for Create, Retrieve, Update, Delete. If you think about it, this is what most applications do:
โจ Create some “resources” ๐ Retrieve them (GET them) ๐จ Update them ๐๏ธ Delete them
๐ฏ Goal
Our API will manage movie data. It will:
โจ Create a new movie, ๐ Retrieve a list of movies or a single movie ๐จ Update a movie
We will build this endpoint:
PUT /movies/:movieId should update a movie (that matches the passed movieId)
๐ You should already have a project using the Node-Starter-Kit. If not, do last week’s prep before you go on.
๐จ PUT
Learning Objectives
PUT /movies/:movieId should update a movie (that matches the passed movieId)
This means that PUT /movies/2
should update an movie with the id 2
and return 200
with JSON { success: true }
to the user.
The code should look something like this:
app.put("/movies/:movieID", (req, res) => {
console.log("PUT /movies route");
});
Remember, you have got to update the movie, not add it to the list.
Test that your API works by updating one of the movies.
Youtube: PUT Codealong with Mitch ๐
๐ช๐พ CRUD Challenges
CHALLENGE 1:
Return the old version of the object you updated as well as the new value in the response
CHALLENGE 2:
Validate the request body to make sure the ID can’t be updated and that users can’t add additional fields
CHALLENGE 3:
Persist your changes to file so that you are able to return your updated values even after you restart the server
Youtube: Reading from the filesystem ๐
Youtube: Writing tests in Postman ๐
๐ฎ ๐งช Test Examples in Postman
Learning Objectives
You will need to create an account with Postman to complete this task. Follow along with the video Writing Tests in Postman with Examples.
activity
Given a user wants to see all the movies, when they make a GET request to
/movies
, then they should receive a list of all the movies.Given a user wants to see a single movie, when they make a GET request to
/movies/:movieId
, then they should receive a single movie.Given a user wants to add a movie, when they make a POST request to
/movies
, then they should receive a success message.Given a user wants to update a movie, when they make a PUT request to
/movies/:movieId
, then they should receive a success message.
Prep Value and Work Not Done
๐ค๐ฝ FeedbackLearning Objectives
Introduction
We donโt have jobs just to fill the time. We should focus our efforts on delivering as much value as we can. You donโt have to finish everything on your to-do list. Whenever you choose to do something, you implicitly choose not to do something else. Learn to identify some tasks that will deliver more value in your available time.
A typical project can be measured at several stages. The latter measures are closer to value, but these are harder to quantify:
- Inputs โ Effort โ Outputs โ Outcomes โ Impact
Measuring Value
๐ฏ Goal: To read and learn about measuring value: its outputs, outcomes, and impact. (30 minutes)
- Read this article.
Five Types of Value
๐ฏ Goal: To read and learn about different types of value. (30 minutes)
- Read this article.