I'm currently working on a React application that's using an internal API endpoint call, which interacts with a DAL layer and writes to a MongoDB hosted online. My issue, I made a less complicated application for a project, and that API call had two variables, like this:
const url = http://localhost:8080/start/dash/${ctx.email}/${ctx.password};
This ended here (which then called my DAL):
``// login user
app.get("/account/login/:email/:password", function (req, res) {
dal.find(req.params.email).then((user) => {
// if user exists, check password
if (user.length > 0) {
if (user[0].password === req.params.password) {
res.send(user[0]);
} else {
res.send("Login failed: wrong password");
}
} else {
res.send("Login failed: user not found");
}
});
});`
`
I now have ELEVEN variables!! Due to the nature and functionality if the new project, I'm needing to pass and write eleven different variables into my call.
Is it okay for my call to be like... Paragraphs long? Is there a better way to do this?
Thank you!
I can technically use the same pattern I have, but I don't know what's a best practice/industry standard as I'm just out of a course. I've also looked around here but there aren't any posts that have helped me with this specifically.
Alright! So through chatting with some friends, the best way to go about this is to package all eleven separate variables into an object, then send that in the request! My DAL (since internal and I can control) will unpack that and assign/write do what it needs to with those variables. Hopefully this helps someone else out there struggling with this!