0
Good morning!
To create a project in JS, EJS and Express.js for studies, to consume a list of cars using webservice: https://carros-springboot.herokuapp.com/api/v1/carros
On the login screen, using: https://carros-springboot.herokuapp.com/api/v2/login
I need to get the JWT token, I need to send a post method with user and password.
There are the steps on this site: http://ricardolecheta.com.br/? p=1106
Anyway, I only used npm "request" feature a few times, I just needed to know if I’m at least on the right track.
Follows the code:
const express = require("express");
const bodyParser = require("body-parser");
const request = require("request");
const app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended: false
}));
// Post
app.post("/", (req, res) => {
let user = req.body.username;
let password = req.body.password;
let options = {
url: "https://carros-springboot.herokuapp.com/api/v2/login",
method: "POST",
contentType: "application/json"
};
request(options, (err, res, body) => {
let carUser = JSON.parse(username.body);
let carPassword = JSON.parse(password.body);
alert(carUser);
alert(carPassword);
});
});
<form action="/" method="post" class="form-signin">
<h1 class="h3 mb-3 font-weight-normal">Login</h1>
<label for="inputEmail" class="sr-only">Username</label>
<input type="username" id="inputUser" class="form-control" placeholder="Username" required autofocus name="username">
<label for="inputPassword" class="sr-only">Password</label>
<input type="password" id="inputPassword" class="form-control" placeholder="Password" required name="password">
<button class="btn btn-md btn-danger" type="submit">Sign in</button>
</form>
Would that be about right? Somebody give a hand?