-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
55 lines (36 loc) · 1.27 KB
/
Copy pathserver.js
File metadata and controls
55 lines (36 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
const axios = require("axios");
const express = require("express");
const app = express();
app.use( express.json() );
app.get("/styles.css", function (req,res){
res.sendFile( __dirname + "/styles.css")
});
app.get("/app", function(req,res) {
res.sendFile( __dirname + "/app.html" );
});
//Send main API request with 3 parameters, receive and label response
app.post("/SearchRequest", async function(req,res){
const response = await axios.get("https://collectionapi.metmuseum.org/public/collection/v1/search",
{params: {q: req.body.q, isHighlight: req.body.isHighlight, medium: req.body.medium}});
res.json(
{
"total": response.data.total,
"objectIDs": response.data.objectIDs
}
)
});
app.post("/ObjectRequest", async function(req,res){
const response = await axios.get("https://collectionapi.metmuseum.org/public/collection/v1/objects/" + req.body.objectID)
res.json(
{
"title": response.data.title,
"artist": response.data.artistDisplayName,
"bio": response.data.artistDisplayBio,
"medium": response.data.medium,
"image": response.data.primaryImageSmall
}
)
});
app.listen(3000, function() {
console.log("Server is listening on port 3000...");
});