-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
32 lines (29 loc) · 856 Bytes
/
index.js
File metadata and controls
32 lines (29 loc) · 856 Bytes
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
const fetch = require("node-fetch");
const getPosts = async (page, username) => {
const query = `
query GetUserArticles($page: Int! , $username: String!) {
user(username: $username) {
publication {
posts(page: $page) {
title
brief
slug
coverImage
}
}
}
}
`;
const variables = { page: page, username: username };
//const user = { username: "bawanthathilan" };
const response = await fetch("https://api.hashnode.com", {
method: "POST",
headers: {
"Content-type": "application/json",
},
body: JSON.stringify({ query, variables }),
});
const ApiResponse = await response.json();
return ApiResponse.data.user.publication.posts;
};
module.exports = { getPosts };