Dies ist eine alte Version des Dokuments!


LU11c - CRUD Server and Postman

  1. How to connect the server to the db
  2. How to fetch data from the db and display it in POSTMAN
  3. How to perform the CRUD operations on the server
  4. How to perform the CRUD operations by using PoSTMAN

At last chapter of our database journey we want to perform all CRUD operations within the server AND the client (POSTMAN). For reasons of efficiency we are going to start with the R = READ of CRUD.

First of all, we want to display the list of users, which are store in the table users. The following code show how to get that list from the database.

// Method to get data from the user table
app.get('/user', (req, res) => {
    const query = 'SELECT * FROM users'; // SQL query to select all rows from user table
    db.query(query, (err, results) => {
        if (err) {
            console.error('Error retrieving users:', err);
            res.status(500).send('Server error');
            return;
        }
        res.json(results); // Send the results as JSON
    });
});

 c_R_ud performance in the presentation (POSTMAN) and logic layer (Node Server)


Volkan Demir

  • modul/m290/learningunits/lu09/theorie/03.1730810325.txt.gz
  • Zuletzt geändert: 2024/11/05 13:38
  • von vdemir