【发布时间】:2021-12-15 04:23:39
【问题描述】:
我正在使用 node 和 express 构建一个 API,它可以使用通用密码加密和解密消息。在我的 API 中,标准路径“格式”是 /
const express = require("express");
const app = express();
const port = 3000;
const checkInput = require("./input_validator");
//import affine cipher utilities
const [affine, reverseAffine, affineKeyValidator] = require("./ciphers/affine");
app.get("/affine/encrypt/:string/:key", (req, res) => {
if (checkInput(req.params.string)) {
let key = JSON.parse("[" + req.params.key + "]");
if (affineKeyValidator(key[0])) {
res.send({ text: affine(req.params.string, key[0], key[1]) });
}
}
});
app.listen(port, () => {
console.log(`Server running on http://localhost:${port}`);
});
以上是我目前的实现。一个示例路径是 /affine/encrypt/hiddenmessage/1,25,它在技术上运行良好,但我觉得这不是实现我正在寻找的最佳方式。有没有更有效的方法来构建它?
【问题讨论】:
-
为什么不在请求正文中创建一个包含所有键的
POST路由?