Skip to content

Commit 52c6b3b

Browse files
committed
📦 NEW: API
1 parent b100ca4 commit 52c6b3b

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

‎books-app/pages/api/search.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import axios from "axios";
2+
3+
export default async function handler(req, res) {
4+
const options = {
5+
method: "GET",
6+
url: `https://hapi-books.p.rapidapi.com/search/${req.query.title}`,
7+
headers: {
8+
"X-RapidAPI-Host": "hapi-books.p.rapidapi.com",
9+
"X-RapidAPI-Key": NEXT_PUBLIC_RAPIDAPI_KEY,
10+
},
11+
};
12+
try {
13+
let response = await axios(options);
14+
res.status(200).json(response.data);
15+
} catch (error) {
16+
console.error(error.response);
17+
}
18+
}

0 commit comments

Comments
 (0)