Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 003b813

Browse files
committed
api-calls have been done.
1 parent 91ae3f3 commit 003b813

File tree

116 files changed

+22157
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

116 files changed

+22157
-0
lines changed

‎day-15/api-calls/adminRequest.js‎

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import axios from "axios";
2+
3+
const url = "http://localhost:8080/api/v1/auth/users";
4+
5+
const body = {
6+
userName: "admin",
7+
password: "admin123456",
8+
};
9+
10+
const getUsers = async () => {
11+
const url = "http://localhost:8080/api/v1/auth/users";
12+
const { status, data } = await axios.get(url);
13+
console.log(status);
14+
console.log(data);
15+
};
16+
17+
const login = async () => {
18+
const body = {
19+
userName: "admin",
20+
password: "admin123456!",
21+
};
22+
23+
const url = "http://localhost:8080/api/v1/auth/login";
24+
return await axios
25+
.post(url, body)
26+
.then((reps) => reps.data.accessToken)
27+
.catch((err) => err.response.status);
28+
};
29+
30+
const postOneCategory = async (accessToken) => {
31+
const url = "http://localhost:8080/api/v1/categories";
32+
33+
const body = {
34+
categoryName: "Axios by Admin",
35+
description: "Api calls trying... by Admin",
36+
};
37+
38+
const config = {
39+
url,
40+
data: body,
41+
method: "post",
42+
headers: {
43+
Authorization: accessToken,
44+
},
45+
};
46+
47+
const { status, data } = await axios(config).catch((err) => console.log(err));
48+
console.log(status);
49+
console.log(data);
50+
};
51+
52+
// getUsers();
53+
await login().then((resp) => {
54+
if (resp !== 401) {
55+
console.log(resp);
56+
} else {
57+
console.log("Error", resp);
58+
}
59+
});
60+
61+
// console.log(accessToken);
62+
// postOneCategory(accessToken);

‎day-15/api-calls/editorRequest.js‎

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import axios from "axios";
2+
3+
const url = "http://localhost:8080/api/v1/auth/users";
4+
5+
const body = {
6+
userName: "editor",
7+
password: "editor123456",
8+
};
9+
10+
const getUsers = async () => {
11+
const url = "http://localhost:8080/api/v1/auth/users";
12+
const { status, data } = await axios.get(url);
13+
console.log(status);
14+
console.log(data);
15+
};
16+
17+
const login = async () => {
18+
const url = "http://localhost:8080/api/v1/auth/login";
19+
const { status, data } = await axios.post(url, body).catch(err => console.log(err.status))
20+
// console.log(status);
21+
// console.log(data)
22+
if (status === 200) return data.accessToken;
23+
else return status;
24+
};
25+
26+
const postOneCategory = async (accessToken) => {
27+
const url = "http://localhost:8080/api/v1/categories";
28+
29+
const body = {
30+
categoryName: "Axios by Editor",
31+
description: "Api calls trying... by Editor",
32+
};
33+
34+
const config = {
35+
url,
36+
data : body,
37+
method:'post',
38+
headers:{
39+
'Authorization' : accessToken
40+
}
41+
}
42+
43+
const { status, data } = await axios(config).catch(err => console.log(err.status))
44+
console.log(status)
45+
console.log(data)
46+
};
47+
48+
// getUsers();
49+
let accessToken='';
50+
accessToken = await login();
51+
console.log(accessToken);
52+
postOneCategory(accessToken);
53+

‎day-15/api-calls/node_modules/.package-lock.json‎

Lines changed: 92 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎day-15/api-calls/node_modules/asynckit/LICENSE‎

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /