Updated on Sep 14, 2023

1

min read

Update a movie

PATCH

You can modify the details of an existing movie in the database using the Movies API. This document provides instructions on how to make a PATCH request to update movie information.

Endpoint

To update a movie, make a PATCH request to the following endpoint:

PATCH /movies/{movie_id}

Replace {movie_id} with the unique identifier of the movie you want to update.

Request

Here's an example of how to make a PATCH request to update movie information using JavaScript:

const movieId = 54321; // Replace with the actual movie ID
const updatedMovieData = {
  title: "Updated Movie Title",
  release_date: "YYYY-MM-DD",
  genre: ["Updated Genre1", "Updated Genre2"],
  director: "Updated Director Name",
  actors: ["Updated Actor 1", "Updated Actor 2"],
  plot: "Updated Movie Plot Description",
  rating: 7.5 // Updated rating (optional)
};

const apiUrl = `https://api.moviesapi.com/v1/movies/${movieId}`;

fetch(apiUrl, {
  method: "PATCH",
  headers: {
    "Content-Type": "application/json"
  },
  body: JSON.stringify(updatedMovieData)
})
  .then(response => response.json())
  .then(data => {
    console.log("Movie Updated:", data);
  })
  .catch(error => {
    console.error("Error:", error);
  });

In this example, we use the fetch function to make an HTTP PATCH request to the specified API endpoint. Replace 54321 with the actual movie ID you want to update and provide the updated movie data.

Response

Upon successful update, the API will respond with the updated movie's details in JSON format, including any changes made to the movie's information.

Response Example

{
  "id": 54321,
  "title": "Updated Movie Title",
  "release_date": "YYYY-MM-DD",
  "genre": ["Updated Genre1", "Updated Genre2"],
  "director": "Updated Director Name",
  "actors": ["Updated Actor 1", "Updated Actor 2"],
  "plot": "Updated Movie Plot Description",
  "rating": 7.5
}

You can now update movie details as needed using the API. Next, we'll cover how to delete a movie from the database.