Skip to content

Commit 386c49b

Browse files
committed
📦 NEW: Created an endpoint to get a list of suggestions
1 parent 1bf0fc6 commit 386c49b

File tree

1 file changed

+38
-0
lines changed
  • wallpaper-generator/pages/api

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
2+
import type { NextApiRequest, NextApiResponse } from "next";
3+
import axios from "axios";
4+
5+
export default async function handler(
6+
req: NextApiRequest,
7+
res: NextApiResponse
8+
) {
9+
if (req.method === "POST") {
10+
const options = {
11+
method: "POST",
12+
url: "https://thefluentme.p.rapidapi.com/generate-post",
13+
headers: {
14+
"content-type": "application/json",
15+
"X-RapidAPI-Key": process.env.RAPIDAPI_KEY,
16+
"X-RapidAPI-Host": "thefluentme.p.rapidapi.com",
17+
},
18+
data: '{"post_title":"Suggest a list with 30 items that contains any word that describes a wallpaper","ai_model":"advanced_01","post_min_length":"199","post_max_length":"500"}',
19+
};
20+
21+
try {
22+
const response = await axios.request(options);
23+
24+
const suggestions: string[] = [];
25+
26+
response.data.ai_post.split(" ").map((word: string) => {
27+
if (!word.match(/[\d.]+/)) {
28+
suggestions.push(word);
29+
}
30+
});
31+
32+
res.status(200).json( suggestions);
33+
} catch (err) {
34+
res.status(500).json({ error: err });
35+
console.log(err);
36+
}
37+
}
38+
}

0 commit comments

Comments
 (0)