Skip to main content

Command Palette

Search for a command to run...

Day 22 of 100days of code.

Published
โ€ข2 min readโ€ขView as Markdown
Day 22 of 100days of code.
P

๐Ÿ‘‹ Hi there! I'm Promise, a passionate MERN Stack Software Developer with a knack for turning ideas into captivating digital experiences. I specialise in creating responsive and user-friendly interfaces that not only meet but exceed the expectations of clients.

Fundamentals of node JS

Handling PATCH Request

The update a response on the server we use 2 methods, The PATCH & PUT method.

PUT method is simply involves when the client modifies the entire resource

PATCH method involves modifying resource but in this case the client sends partial data that is updated without modifying the entire data

To update a movie on the list we use the ID to target a specific movie. To achieve this we also need to send the request body of the data. Lets say we want to update or change the release year of the movie with ID = 2. Using Postman or thunder client, Lets update the release year๐Ÿ‘‡๐Ÿผ

Lets use the PUT request method. And even though we are only updating the release year property object, we still need the entire object in the request body. But if we use the PATCH method, e don't need to send the entire object, we only send the property we want to update. ๐Ÿ‘‡๐Ÿผ

We want to create an API and when a request is sent to the resource we want to update a movie. Lets create the endpoint and write some logic. First we need to identify the movie object we want to update using the ID๐Ÿ‘‡๐Ÿผ

Lets see the response on the server, The response was successfully updated๐Ÿ‘‡๐Ÿผ

The object was also updated in our movies.json file as well ๐Ÿ‘‡๐Ÿผ

Lets update our by writing a logic to handle errors for cases where the client pass a non existing route parameter or ID๐Ÿ‘‡๐Ÿผ

Lets see the error response on the server when we pass in a non existing route parameter or ID๐Ÿ‘‡๐Ÿผ

That's all for this lesson.

Next: Handling DELETE Requests

See you soon๐Ÿ˜Š๐ŸซกโœŒ๐Ÿผ...

More from this blog

Untitled Publication

36 posts