CREATING SQL SERVER REST API
1) create project folder, ZNODES4.
2) copy package.json
3) Install package
3.1.) in the project folder, run "npm install" .
or,
3.2.) copy the folder "nodes_modules" into the project folder.
copy the folder "_middleware" .
4) Create the script file, "server.js"
copy the "server.js" file from project ZNODES3, change the statement:
edit
// api routes
app.get('/', (req, res) => {
res.send('Hello World!')
})
//app.use('/users', require('./users/users.controller'));
app.use('/users', require('./users/users.controller'));
to ...
app.use('/customers', require('./customers/customers.controller'));
5) Create a folder "customers".
6) Create customers script files.
6.1) customer.model.js
6.2) customer.service.js
6.3) customers.controller.js
7) Edit customers.controllers.js
Copy the file from ZNODES3/users/users.controller.js
Change the statement
const userService = require('./user.service');
to
const userService = require('./customer.service');
Change the phrase "message: 'User "
to
"message: 'Customer "
8) Edit customer.service.js
CREATE CUSTOME HTML FORM
1) edit server.js
app.get('/', (req, res) => {
res.sendFile(__dirname + '/views/new.html');
})
2. create folder "views".
3. create file "new.html"
copy the following codes
<!DOCTYPE html>
<html>
<body>
<h2>HTML Forms</h2>
<form method="post" action="/customers">
<label for="title">Title:</label><br>
<input type="text" id="title" name="title" value="Mr"><br>
<label for="fname">First name:</label><br>
<input type="text" id="firstName" name="firstName" value="John"><br>
<label for="lname">Last name:</label><br>
<input type="text" id="lastName" name="lastName" value="Doe"><br><br>
<label for="role">Role:</label><br>
<input type="text" id="role" name="role" value="Customer"><br>
<label for="email">Email:</label><br>
<input type="text" id="email" name="email" value="a@a.com"><br>
<label for="password">Password:</label><br>
<input type="password" id="password" name="password" value="12345678"><br>
<label for="confirmPassword">Confirm nPassword:</label><br>
<input type="password" id="confirmPassword" name="confirmPassword" value="12345678"><br>
<input type="submit" value="Submit">
</form>
</body>
</html>