Split API from demo app and began Express framework (#7)

justin/oap-21
Peter Rauscher 2022-10-06 18:49:58 +00:00 committed by GitHub
parent 0f247eac8c
commit 4d7afab630
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 1073 additions and 0 deletions

1
api/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
node_modules/

16
api/app.js Normal file
View File

@ -0,0 +1,16 @@
const express = require("express");
const app = express();
const apiRoutes = require("routes");
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use("/api", apiRoutes);
app.use("*", (req, res) => {
res.status(404).json({ error: "Resource not found" });
});
app.listen(3000, () => {
console.log("Suggestion Service API is up!");
});

1018
api/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

14
api/package.json Normal file
View File

@ -0,0 +1,14 @@
{
"name": "oapen-suggestion-service-api",
"version": "0.0.1",
"description": "An API which allows you to search for books with similar content from the oapen.org library.",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.18.1"
}
}

16
api/routes.js Normal file
View File

@ -0,0 +1,16 @@
const express = require("express");
const router = express.Router();
const validate = require("./validate");
router.get("/:handle", async (req, res) => {
try {
await validate.checkHandle(req.params.handle);
//TODO: Call a data function to grab suggestions from DB
let responseData = { error: "Not implemented" };
res.status(200).json(responseData);
} catch (e) {
res.status(200).json({});
}
});
module.exports = router;

8
api/validate.js Normal file
View File

@ -0,0 +1,8 @@
let checkHandle = async (handle) => {
// TODO: Validate the book's handle
return true;
};
module.exports = {
checkHandle,
};