Simple API build in Nodejs, Express and SQL Server database.
run the script inside the folder scripts sql (create database and table)
modify config.js with your database configuration.
npm install
and
npm run dev (node monitor watching changes and restart server)
or
npm run start
Instructions (use Postman)
- To create a user, send in the request body: (POST - http://localhost:8080/api/user)
Request Object { "FirstName": "Demo", "LastName":"User", "Username":"demo-user", "Email":"user@demo.com", "Password": "Demo123" } Response Object { "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwiaWF0IjoxNTU5NTYxNDc2LCJleHAiOjE1NTk2NDc4NzZ9.vgjkGT2Do1D1y7mrzXWMPT3ENOBlJOZVeekeksWTf-Q", "message":"Succesfully created user" }
- To do the login: (POST - http://localhost:8080/api/user/login)
Request Object { "Username":"demo-user", "Password": "Demo123" } Response Object { "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwiaWF0IjoxNTU5NTYxNDc2LCJleHAiOjE1NTk2NDc4NzZ9.vgjkGT2Do1D1y7mrzXWMPT3ENOBlJOZVeekeksWTf-Q", "message": "User succesfully login" }
- Access a protected route: (GET - http://localhost:8080/api/user)
--add this line in the header request Key Value x-access-token eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwiaWF0IjoxNTU5NTYxNDc2LCJleHAiOjE1NTk2NDc4NzZ9.vgjkGT2Do1D1y7mrzXWMPT3ENOBlJOZVeekeksWTf-Q