#35 API: Handling POST Request | Working with Express JS | A Complete NODE JS Course

Поділитися
Вставка
  • Опубліковано 18 гру 2024

КОМЕНТАРІ • 15

  • @MuhammadUsman-ok5vs
    @MuhammadUsman-ok5vs 8 місяців тому +2

    Awesome Explanation

  • @peterkabiru5144
    @peterkabiru5144 Рік тому +2

    Well explained. I'm Grateful🙏

  • @MdKaif-iy5je
    @MdKaif-iy5je 8 місяців тому +2

    Well explained sir!

  • @KnowledgeMirrorHindi
    @KnowledgeMirrorHindi 3 місяці тому

    @procademy I have an issue where, after making a POST call, the new data is successfully saved in the JSON file. However, when I make a GET request to retrieve all the movies, only the old records are returned, and the newly added movie doesn't show up. If I restart the server and then make the GET call again, it returns all the movies, including the new one.

  • @HaamroNotes
    @HaamroNotes 3 місяці тому

    the middleware express.json() is responsible for parsing incoming request bodies that contain JSON data into js objects. Without this middleware, the body of the request (for example, the data sent via Postman in a POST request) would not be parsed, leaving request.body undefined.

  • @Kiran-khadka
    @Kiran-khadka 2 роки тому +2

    Undoubtedly, your content is great!
    Can you help where can I get resources for further practice and learning thought it seems obvious to someone but there lot of resources in the internet:
    How to find great resource and keep upskilling ownself:
    I'm looking forward for your kind
    Reply 🖤

    • @m7mdMAH5
      @m7mdMAH5 3 місяці тому

      I am not a professional but I would recommend chatGPT, there's many questions that I would feel embarrassed to ask humans because it feels it should be obvious but with AI I can ask it 99999 silly questions and it would replay with structured, clear replies!

  • @Dext-err
    @Dext-err Рік тому

    req.body is undefined only the id is added whit 201 status m using express "^4.18.2"
    great explanation by the way thank u so much!

    • @Dext-err
      @Dext-err Рік тому

      ```JS
      app.post('/api/v1/movies', (req, res) => {
      console.log(req.body)
      const newId = movies[movies.length - 1].id + 1
      const newMovie = Object.assign({id: newId}, req.body)
      movies.push(newMovie)
      fs.writeFile('./Data/movies.json', JSON.stringify(movies), (err) => {
      res.status(201).json({
      status: "created!",
      data: {
      movie: newMovie
      }
      })
      })
      })
      ```

  • @hassannouri9796
    @hassannouri9796 7 місяців тому

    ❤❤❤

  • @DecoyCheats
    @DecoyCheats Рік тому

    I'm only getting curly braces {} with nothing in them, despite the countless times I have reviewed my code.
    what could be the issue here?

    • @procademy
      @procademy  Рік тому

      Can you please post your post api code here?

    • @DecoyCheats
      @DecoyCheats Рік тому

      Thank you,,, but I already figured.@@procademy

  • @igorr4682
    @igorr4682 2 роки тому +3

    Why not use spread operator to create a new object ? const newMovie = {id:newId, ...reg.body}

    • @procademy
      @procademy  2 роки тому +3

      Yes you can do that...that is also an option.