Introduction to POSTMAN for REST API's

Поделиться
HTML-код
  • Опубликовано: 10 сен 2024
  • Hey Everyone, In this video, we will build our own REST API using Node and Express frameworks.
    Fake Data API: www.mockaroo.com/
    ► Complete Full Stack Web Developer RoadMap 2023: • Complete Full Stack We...
    ► Master NodeJS Playlist: • Master NodeJS
    Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine. It allows developers to run JavaScript on the server side, creating server-side applications with JavaScript.
    ► My Website: www.piyushgarg...
    My Gears
    ► My Girlfriend: amzn.to/3WD6FRp
    ► Apple MacBook Laptop: amzn.to/3WBJgQn
    ► Anker USB Hub: amzn.to/3GhZSr0
    ► Blue Yeti Microphone: amzn.to/3YKZ9FT
    ► External 27” Monitor: amzn.to/3Vp3xaO
    ► Logitech MK295 Wireless Keyboard and Mouse: amzn.to/3DuL1bB
    ► Seagate Expansion 1TB External HDD: amzn.to/3QMm5Q8
    ► Tripod: amzn.to/3S4OwK4
    ► Ring Light: amzn.to/3YLf8DR
    Disclaimer: All the links above are affiliate links.
    Social Links
    ► Twitter - / piyushgarg_dev
    ► LinkedIn - / piyushgarg195
    Video Titles
    What is NodeJS?
    What is REST API?
    How to design restful API?
    REST API Best Practices
    Tags
    #nodejs #javascript #expressjs #mernstack #developer #api #https #server #javascriptinhindi #webdevelopment #webapp #realtimeapp #serverside #nonblockingio #tech

Комментарии • 133

  • @raghavpal4219
    @raghavpal4219 Год назад +16

    The way you simplify things 🔥>>>>

  • @surajkumar-vd4je
    @surajkumar-vd4je Год назад +10

    "Making difficult concepts easy" is the quality that differentiats Piyush from other trainers

  • @bytebreaks
    @bytebreaks 2 месяца назад +1

    Hey Piyush
    I really liked your Node.js backend tutorials! You have explained very clearly and step-by-step. Now I can confidently use Node.js in my projects. I have truly become a big fan of your hard work and dedication. Thanks a lot for sharing your knowledge

  • @anurajrajput4474
    @anurajrajput4474 11 месяцев назад +4

    You are simplifying many things and making them freely accessible to a lot of people. No amount of gratitude can truly suffice. 💙🙏🙌

    • @varunupadhyay2488
      @varunupadhyay2488 8 месяцев назад

      Have you made Piyush Garg's Node.js notes? I've been through the whole playlist, but my notebook is misplaced. Got an interview in two days, and I'm a bit stuck. Any chance you could share your notes?

  • @rishabhraj8233
    @rishabhraj8233 8 месяцев назад +17

    patch method:
    const id = Number(req.params.id);
    const body = req.body;
    const user = users.find((user) => user.id === id)
    const updatedUser = { ...user, ...body };
    updatedUser.id=id;
    users[id-1]=updatedUser
    fs.writeFile('MOCK_DATA.json', JSON.stringify(users), (err, data) => {
    return res.json({ status: "Success", updatedUser })})

    • @siddharthjaiswal9942
      @siddharthjaiswal9942 5 месяцев назад +1

      purpose of this line?
      updatedUser.id=id;

    • @AshishKumar-qt5gs
      @AshishKumar-qt5gs 5 месяцев назад

      @@siddharthjaiswal9942 This line ensures that the id of the updated user matches the id extracted from the request URL.

    • @mayankjain7910
      @mayankjain7910 4 месяца назад +1

      no use

    • @shubhambera2942
      @shubhambera2942 Месяц назад +1

      users[id-1]=updatedUser
      meaning of this line?

    • @iamnotfamous6591
      @iamnotfamous6591 11 дней назад

      @@shubhambera2942 we have to do it because we use array here indexing start with 0 if we give id= 1001 in header its work as a array index so users[1001] add new user not updating the data. you can console log this to check. ex: user[1000] will give you //the 999th user's data. he use spread operator to add two array of object into a single object and spread operator overwritten the values if two keys in the passing objects are same. so user's data will be overwritten by the body's data and store into new object updatedUser.

  • @rohansingh6329
    @rohansingh6329 4 месяца назад +1

    watched some videos from other youtubers on backend when i was starting was not able to understand from them their teaching was difficult to understand but you made it seem so easy thanks for this playlist i will watch all the videos 👌👌

  • @sachinandanprasad7618
    @sachinandanprasad7618 11 месяцев назад +5

    u'r awosome..........
    most underrated play list

  • @iamakashkumarram
    @iamakashkumarram Год назад +7

    This is called quality content.

  • @malikmubashir2597
    @malikmubashir2597 8 месяцев назад +16

    teach everything what you can

    • @as_if
      @as_if 6 месяцев назад

      😭

  • @brosgaming108
    @brosgaming108 Год назад +6

    Another level simplification 🧡

  • @yashmehta9953
    @yashmehta9953 3 месяца назад +1

    Also you can use thunder client instead of postman. It is an extension of vs code

  • @lakshaysharma8364
    @lakshaysharma8364 Год назад +2

    Bro you are best at teaching .. Continue helping us forever

  • @nishu20501
    @nishu20501 4 месяца назад

    both assignments completed
    finally learnt how to use splice method in array.

  • @SouravYadav-uf6yk
    @SouravYadav-uf6yk Год назад +3

    First of all I must say awesome teaching.I found you first on Codedman in Redux Toolkit Module then I search in youtube.I completed Codedamn basic nodejs course but things were not clear than I continue your nodejs series.Thanks a lot for this.
    I Tried Patch Api but index value was undefined then what should i do

    • @piyushgargdev
      @piyushgargdev  Год назад +2

      Hey, First of all, Thanks a lot.
      Second: I didn't got your doubt, please mention more details

    • @varunupadhyay2488
      @varunupadhyay2488 8 месяцев назад

      Have you made Piyush Garg's Node.js notes? I've been through the whole playlist & have made my notes but my notebook is misplaced. Got an interview in two days, and I'm a bit stuck. Any chance you could share your notes?

    • @khyatichaudhary4083
      @khyatichaudhary4083 8 месяцев назад

      ​Do you need them now​?@@varunupadhyay2488

    • @hersheynaik3029
      @hersheynaik3029 8 месяцев назад

      @@varunupadhyay2488 How was your interview?

  • @tenzin.tsundue1
    @tenzin.tsundue1 Месяц назад

    If anyone is facing difficulties in writing the updated object on json file with patch method, then try overwriting the json file manually and change the file to overwrite mode then we can update or write on the file from fs.writeFile method.

  • @RahulKumar-ed9vw
    @RahulKumar-ed9vw 19 дней назад

    Thanks bhaiya. You are a great teacher.

  • @badalkamli7816
    @badalkamli7816 Год назад +11

    Amazingly explained. Thank you 💙
    DELETE request:
    app.delete("/api/users/:id", (req, res) => {
    //Get the id of the user
    const id = Number(req.params.id);
    //Find out the index of the user with above id from the array "users"
    const userIdx = users.findIndex((user)=> user.id === id);
    //Get the deleted user object using splice. Mind we need to get the object and not array as returned by splice method, so '[0]' satisfies this requirement. The resulting object is just for the sake of displaying, you may neglect storing it if you don't want to display.
    const delUser = users.splice(userIdx, 1)[0];
    //Write the changes into the json file.
    fs.writeFile("./MOCK_DATA.json", JSON.stringify(users), (err, data) => {
    return res.json({ status: "success", delUser });
    });
    })

    • @pavant4391
      @pavant4391 8 месяцев назад

      thank u for code!! It
      helps

    • @madmax180
      @madmax180 7 месяцев назад

      hey@@pavant4391can you tell me how [0] helps solve this object problem???

    • @Ayush37262
      @Ayush37262 7 месяцев назад

      ​@@madmax180users.splice contains an array with one object... So that's why we are using [0]

    • @rishabhkedia9304
      @rishabhkedia9304 2 месяца назад

      After this there must be a change in POST as well, as new user being created will have glitch in ID, if any middle element is deleted from array.
      as POST included users.length + 1 as new userID

  • @jatilyadav4000
    @jatilyadav4000 Год назад +2

    Amazing Video.... Great Explaination... Thank you soo much

  • @Torpedo91
    @Torpedo91 7 месяцев назад +4

    for anybody whose program is not creating new entry in user.json,
    1.) Try to console.log() the users after pushing the new entry.
    2.) If you see the new entry there, and the code doesn't have syntax mistake then the problem is directory path of user.json
    copy this code and paste it in the program,
    const file_path = __dirname + '/users.json';
    put this file_path in fs.writefile and try again.

    • @shrutipawar4794
      @shrutipawar4794 5 месяцев назад +1

      for me only the new ids are getting added in the data and not the entire user info ...anything you could suggest?

    • @Torpedo91
      @Torpedo91 5 месяцев назад

      @@shrutipawar4794 did you tried pasting the code in chatgpt?

    • @mayanksinha1883
      @mayanksinha1883 3 месяца назад

      @@shrutipawar4794 had the same problem make sure selecting body in postman while filling the data

  • @priyanshukumar6679
    @priyanshukumar6679 2 месяца назад

    Thanku bahut badiya explanation I have ever seen

  • @shubhammali2109
    @shubhammali2109 5 месяцев назад

    You are the greatest of all time, Thank you so much for sharing this gold!

  • @iamakashkumarram
    @iamakashkumarram Год назад +3

    Awesome teaching style

  • @technologicalvivek7510
    @technologicalvivek7510 6 месяцев назад

    Aaj aache se Rest API samajh me aayi meko.Thank you bhaiya .

  • @shubhamtaluja9770
    @shubhamtaluja9770 7 месяцев назад +1

    You gained a subscriber, keep up the nice work. :)

  • @surajkumar-vd4je
    @surajkumar-vd4je Год назад +1

    "Node Js made easy" perfect name for this series.

  • @CopyCoderX
    @CopyCoderX 11 дней назад

    solute for great mind❤❤❤❤

  • @sameerfaridi2
    @sameerfaridi2 10 месяцев назад

    homework done , this is best series of nodeJs

  • @poojaganvir5631
    @poojaganvir5631 7 месяцев назад +1

    Great explanation , thank you

  • @tusharsingh1915
    @tusharsingh1915 2 месяца назад +1

    To all the people installing postman on their system, Now Postman is also available as a extension in vscode, So i think their is no need to switch a tab and you are good to go:)

    • @deshbhaktaadmi6580
      @deshbhaktaadmi6580 6 дней назад

      Better use thunder client extension

    • @tusharsingh1915
      @tusharsingh1915 6 дней назад

      @@deshbhaktaadmi6580 yeahh, another competitor of postman👍

  • @weforyouweb1165
    @weforyouweb1165 Год назад +2

    Superb content 🎉

  • @shi-nee7966
    @shi-nee7966 Год назад

    amaazinnggglyy explained oofe...💯💥

  • @sumirandahal76
    @sumirandahal76 6 месяцев назад

    thank you sir best teaching

  • @Wahab00916
    @Wahab00916 6 месяцев назад

    love you soo much soo owesome explanation always😍

  • @namannema3349
    @namannema3349 4 месяца назад

    awesome bhaiya thank you got it all

  • @pawansoni630
    @pawansoni630 Месяц назад +1

    Bhaiya aap esme file write kr rhe ho wo v 1000 + new data esse server pr jada burden nhi jaega
    In place of File write again again can we use apendfile operation to reduce the burden on server if yes so please reply 🙏

    • @pawansoni630
      @pawansoni630 Месяц назад

      Step 1 File write with 1000 users
      Step 2 Append new user so first copy 1000 users and add new one also with deleting 1000 users from file
      Step 3 rewrite the file with 1001 users

  • @govindkrishnamishra-km8tj
    @govindkrishnamishra-km8tj Год назад +2

    Thanks a lottt

  • @Error404Codes
    @Error404Codes Год назад +1

    lost of love from nepal . you deserve more subscribe . you content is too much good

  • @hamudxd9497
    @hamudxd9497 20 дней назад

  • @stewie__69
    @stewie__69 2 месяца назад

    Thunder client, a vs code extension is the best alternative to Postman.

  • @kumarinisha7289
    @kumarinisha7289 Месяц назад

    when I am using post method an error occured (cannot post/api/users)

  • @saurabhmaurya4199
    @saurabhmaurya4199 5 дней назад

    name of vs code extension for node js??

  • @santoshbhujbal5650
    @santoshbhujbal5650 2 месяца назад

    Sir post request problem kya aaraha he ki postman par data dikha Raha hai lekin json file mai data fetch nahi ho raha hai please help

  • @tusharsingh1915
    @tusharsingh1915 2 месяца назад +1

    Abb lgg rha hai..backend padh rha hu👌🥲

  • @abhayyraz
    @abhayyraz 2 месяца назад

    Good One

  • @vivekprajapati5463
    @vivekprajapati5463 2 месяца назад

    Kindly make a playlist of api

  • @akankshaa_1210
    @akankshaa_1210 5 месяцев назад

    hi piyush , my post thing is not working , on the url i am getting can not get /api/user, could you please help

  • @user-nz8de4hc6z
    @user-nz8de4hc6z 7 месяцев назад +1

    push k andr ...body kyun? dots k bina bhi body likh saqty naaa?

    • @flopgameryt399
      @flopgameryt399 6 месяцев назад +1

      Because id ko khudse dal raha hai hum
      Without dot kroga toh bi ho jayega push but id nahi aayega
      So to give id hum spread kr rha hai apna object ko

  • @iuseitnowone2028
    @iuseitnowone2028 Год назад

    so we used fs module to write to the file, but did not use it to read the file.. why?

  • @SulavGhimireeee
    @SulavGhimireeee 8 месяцев назад

    Thanks bro

  • @ArunKumar_237
    @ArunKumar_237 2 месяца назад

    super

  • @ketanjadhav4328
    @ketanjadhav4328 3 месяца назад

    Which theme you are using ?

  • @rdnexta
    @rdnexta 5 месяцев назад

    plz sir can you say your vs code theme name. btw, very good video. all not this one.

  • @VikasSharma-kc2oc
    @VikasSharma-kc2oc Год назад

    🔥🔥

  • @user-rn8ix7gp2g
    @user-rn8ix7gp2g 5 месяцев назад

    guru jiiiiiiii

  • @AMAR-pc6ht
    @AMAR-pc6ht 8 месяцев назад +1

    12:35 I got the issue beforehand😅 so removed +1

  • @saubhagyalive3061
    @saubhagyalive3061 Год назад

    TypeError: Cannot read properties of undefined (reading 'json')
    I am getting this error while returning the res.json({status:"success"})

    • @user-ft1kl4xq4u
      @user-ft1kl4xq4u 4 месяца назад

      instead of res.json({status:"success"}) use res.send({status:"success"})

  • @user-rw5oc3df9k
    @user-rw5oc3df9k 8 месяцев назад

    not able to delete using fs.unlink but some error

  • @bilalnaeem2985
    @bilalnaeem2985 7 месяцев назад

    sir ly ❤

  • @user-dz8gx6ke1k
    @user-dz8gx6ke1k 7 месяцев назад

    after adding multiple users, the mock users.json file is not getting updated. Is this supposed to happen or is my server failing? I can only see the first entry and after that it shows on postman but not in my mock json file

    • @Aitool-r3q
      @Aitool-r3q 7 месяцев назад

      // Do This 👍👍
      app.post('/api/users', (req, res) => {
      const body = req.body;
      users.push({...body, id: users.length + 1})
      fs.writeFile('./MOCK_DATA.json', JSON.stringify(users), (err, data) => {
      return res.json({status: "Success", id: users.length})
      })
      })

    • @pratham9987
      @pratham9987 7 месяцев назад +1

      @@Aitool-r3q Video mai same code haina ?

  • @saranyasingh6847
    @saranyasingh6847 Год назад

    for me data of new user is getting updated on localhost:8000/api/users but not in MOCK_DATA.json file in vs code . pls help.

    • @Ankit-01-01
      @Ankit-01-01 11 месяцев назад

      fs.writeFile("./MOCK_DATA.json", JSON.stringify(users), (err, data) => {
      return res.json({ status: "success" });
      });

    • @varunupadhyay2488
      @varunupadhyay2488 8 месяцев назад

      Have you made Piyush Garg's Node.js notes? I've been through the whole playlist & have made my notes but my notebook is misplaced. Got an interview in two days, and I'm a bit stuck. Any chance you could share your notes?

  • @dishagupta6231
    @dishagupta6231 Год назад

    please make a crash course on mern stack

  • @mma-dost
    @mma-dost Год назад +1

    👌👍👍👌👌👍

  • @rshan7375
    @rshan7375 6 месяцев назад

    ThunderClient use karne se aur aasan hota

  • @RAVIKUMAR-md3vk
    @RAVIKUMAR-md3vk 2 месяца назад

    kos ->king of simplifier

  • @karitayade3354
    @karitayade3354 4 месяца назад

    doing POST i got error 404 not found

  • @khushijain6993
    @khushijain6993 7 месяцев назад

    Your video was very helpful!
    But I've got problem with the patch request I am making. The data I want to update is returned as it is. Its not getting updated. I am giving my code for reference.
    app.patch('/api/users/:id',(req, res) => {
    const id = Number (req.params.id)
    let user = users.find (user => user.id === id)
    const idx = users.indexOf (user);
    const newObj = Object.assign (user , req.body)
    users[idx] = newObj;
    fs.writeFile ('./MOCK_DATA.json',JSON.stringify(users) , (err,data) => {
    return res.json ({
    status: "success",
    users: user
    })
    })
    })
    I am passing raw data in body in postman such as {"job_title": "Data Analyst"} but no updation is happening. Can anyone please help?

    • @khushijain6993
      @khushijain6993 7 месяцев назад

      I am unable to go forward in the playlist since my doubt remains uncleared. Thought I would watch this playlist completely... Thankyou for uplaoding good videos.

    • @itsd2388
      @itsd2388 5 месяцев назад

      @@khushijain6993 same problem i have invested 2 hrs, but still not resolved. Did you get it resolved please tell

    • @itsd2388
      @itsd2388 5 месяцев назад +1

      app.use(express.json()); we have to use this middleware finally it ran 😭

    • @khushijain6993
      @khushijain6993 5 месяцев назад

      @@itsd2388 thankyou for telling 🥲

  • @surajkharkwal7122
    @surajkharkwal7122 11 месяцев назад

    sur voice bahut kam ati hai apki

    • @pkyadav6230
      @pkyadav6230 9 месяцев назад

      Mere ko to a rhi hai ,Yes he has High pitch

  • @itsd2388
    @itsd2388 5 месяцев назад

    const id = Number(req.params.id);
    let user = users.find((user) => user.id === id);
    if (!user) {
    return res.status(404).json({
    status: "fail"
    })
    }
    console.log(user);
    const ind = users.indexOf(user);
    const body = req.body
    console.log(body);
    Object.assign(user, body );
    console.log(user);
    users[ind]=user;

    fs.writeFile("./MOCK_DATA.json",JSON.stringify(users),(err,data)=>{
    return res.json({status: "succuess",data: { user}})
    })
    it s not updating for patch i have tried everyway

  • @lucky-laxmi4799
    @lucky-laxmi4799 5 месяцев назад

    delete method:
    .delete("/api/users/:id", (req, res) => {
    const id = Number(req.params.id);
    const index = users.findIndex((index) => index.id === id);
    if (index !== -1) {
    users.splice(index, 1);
    }

    return res.json({status: "Successfully Removed"});
    })

  • @Rajeshmaurya-tz9ez
    @Rajeshmaurya-tz9ez 9 дней назад

    ## The same code below did not work before I shut down my laptop; however, it worked after I did so. Before that, I was wondering what was wrong with it ##
    app.patch("/api/users",(req, res) => {
    // Edit user with id
    const body = req.body;
    console.log("Body:", body);
    const editedUser = users.map((user) =>
    user.id == body.id
    ? {
    ...user,
    first_name: body.first_name,
    last_name: body.last_name,
    email: body.email,
    job_title: body.job_title,
    }
    : user
    );
    fs.writeFile(
    "./MOCK_DATA.json",
    JSON.stringify(editedUser),
    (error, data) => {
    if (error) {
    console.log("Error:", error);
    return res.json({ status: "Error" });
    } else {
    return res.json({ status: "Update" });
    }
    }
    );
    });)

  • @darkknight-rp2ry
    @darkknight-rp2ry 3 месяца назад +1

    🫡🫡🫡🇮🇳❤️

  • @deeppanchal9567
    @deeppanchal9567 Год назад +10

    Here is a Solution for the Patch request
    Hope it Helps
    app.route("/api/users/:id")
    .patch((req, res) => {
    // getId stores the Id from the given Parameters in the URL.
    const getId = Number(req.params.id);
    // body stores the body in which we've to make changes.
    const body = req.body;
    // Finding the user Id from the user array.
    const userIndex = users.findIndex((user) => user.id === getId);
    // If we found a user with its Id then gotUser stores that object.
    const gotUser = users[userIndex];
    // Here gotUser has the user Object and body has the changes we have to made.
    const updatedUser = { ...gotUser, ...body};
    // After Merging them, Update the users Array.
    users[userIndex] = updatedUser;
    // Lastly, write the changes into the json file.
    fs.writeFile('./users_mock_data.json', JSON.stringify(users), (err, data) => {
    return res.json({ status: "Success", updatedUser});
    })
    })

    • @user-rw8en1jp4t
      @user-rw8en1jp4t 11 месяцев назад

      Thanks!, this solution is very readable and clear

    • @hidev4615
      @hidev4615 10 месяцев назад +1

      this can be done using map easily,
      //you should update this logic:
      .patch((req, res) => {
      const id = Number(req.params.id);
      const { last_name } = req.body;
      const newUsers = users.map((user) => {
      if (user.id === id) {
      return { ...user, last_name };
      } else {
      return user;
      }
      });
      fs.writeFile('./MOCK_DATA.json', JSON.stringify(newUsers), (err, data) => {
      return res.json({ status: 'successfully edited user', id });
      });
      })

    • @bakchoditank
      @bakchoditank 8 месяцев назад

      but time complexity is very high if we are using map function@@hidev4615

    • @Ayush37262
      @Ayush37262 7 месяцев назад

      ​@@hidev4615 will it update the users array??

  • @user-de2jj7vl4r
    @user-de2jj7vl4r 6 месяцев назад

    .delete((req,res)=>{

    //TODO: Delete the user with id
    const id = Number(req.params.id)
    if(id!=-1 && users.length>=id){
    users.splice(id-1,1);
    fs.writeFile("./MOCK_DATA.json",JSON.stringify(users),(err,data)=>{
    if(!err){
    return res.status(200).json({success:"User delete"});
    }else{
    res.status(500).json({error:"Failed to delete user"});
    }
    });
    }else{
    return res.status(404).json({error:"User not found"});
    }
    });

  • @sahaj.arora_
    @sahaj.arora_ 6 месяцев назад

    app.delete("/api/users/:id", (req, res) => {
    let { id } = req.params;
    //let's delete our user
    users = users.filter((user) => user.id !== parseInt(id));
    //converting users into JSON compatible format
    users = JSON.stringify(users);
    //writing into users.json file
    fs.writeFile("./user_data/users.json", users, (error) => {
    if (error) {
    return res.status(500).json({ error: "delete operation failed!" });
    }
    return res.json({ success: "user_details deleted successfully!" });
    });
    });