Comment
Definition
- JSON
- Typescript
comment.json
{
"id": 0,
"articleID": 0,
"userID": 0,
"commentTitle": "",
"commentContent": "",
"status": 0,
"createdAt": "",
"updatedAt": "",
}
comment.ts
export interface IComment {
id: number;
articleID: number;
userID: number;
commentTitle: string;
commentContent: string;
status: number;
createdAt: Date | null;
updatedAt: Date | null;
}
Get Comments
- Curl
- Typescript
curl -X GET "${baseUrl}/comment/?filter=${filter}&orderBy=${orderBy}&page=${page}&pageSize=${pageSize}" \
-H "Authorization: Bearer ${accessToken}" \
-H "Content-Type: application/json" \
-H "Accept: application/json"
const response = await fetch("${baseUrl}/comment/?filter=${filter}&orderBy=${orderBy}&page=${page}&pageSize=${pageSize}", {
method: "GET",
headers: {
"Content-Type": "application/json",
"Accept": "application/json",
"Authorization": `Bearer ${accessToken}`,
},
})
const data = await response.json();
if (!response.ok) {
throw new Error(data);
}
Get Comment
- Curl
- Typescript
curl -X GET "${baseUrl}/comment/${id}" \
-H "Authorization: Bearer ${accessToken}" \
-H "Content-Type: application/json" \
-H "Accept: application/json"
const response = await fetch("${baseUrl}/comment/${id}", {
method: "GET",
headers: {
"Content-Type": "application/json",
"Accept": "application/json",
"Authorization": `Bearer ${accessToken}`,
},
})
const data = await response.json();
if (!response.ok) {
throw new Error(data);
}
Apply Comment.ID
- Curl
- Typescript
curl -X POST "${baseUrl}/apply/comment/id/" \
-H "Authorization: Bearer ${accessToken}" \
-H "Content-Type: application/json" \
-H "Accept: application/json"
const response = await fetch("${baseUrl}/apply/comment/id/", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Accept": "application/json",
"Authorization": `Bearer ${accessToken}`,
},
body: JSON.stringify(payload),
})
const data = await response.json();
if (!response.ok) {
throw new Error(data);
}
Create Comment
- Curl
- Typescript
curl -X POST "${baseUrl}/comment/" \
-H "Authorization: Bearer ${accessToken}" \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d @comment.json
info
comment.json
{
"articleID": 0,
"userID": 0,
"commentTitle": "",
"commentContent": "",
"status": 0,
}
tip
success status: 201
const response = await fetch("${baseUrl}/comment/", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Accept": "application/json",
"Authorization": `Bearer ${accessToken}`,
},
body: JSON.stringify(payload),
})
const data = await response.json();
if (!response.ok) {
throw new Error(data);
}
Update Comment
- Curl
- Typescript
#!/bin/bash
curl -X PUT "${baseUrl}/comment/${id}" \
-H "Authorization: Bearer ${accessToken}" \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d @comment.json
info
comment.json
{
"articleID": 0,
"userID": 0,
"commentTitle": "",
"commentContent": "",
"status": 0,
}
const response = await fetch("${baseUrl}/comment/${id}", {
method: "PUT",
headers: {
"Content-Type": "application/json",
"Accept": "application/json",
"Authorization": `Bearer ${accessToken}`,
},
body: JSON.stringify(payload),
})
const data = await response.json();
if (!response.ok) {
throw new Error(data);
}
Patch Comment
- Curl
- Typescript
curl -X PATCH "${baseUrl}/comment/${id}" \
-H "Authorization: Bearer ${accessToken}" \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-H "Attrs: articleID,userID,commentTitle,commentContent,status" \
-d @comment.json
info
comment.json
{
"articleID": 0,
"userID": 0,
"commentTitle": "",
"commentContent": "",
"status": 0,
}
const response = await fetch("${baseUrl}/comment/${id}", {
method: "PATCH",
headers: {
"Content-Type": "application/json",
"Accept": "application/json",
"Authorization": `Bearer ${accessToken}`,
"Attrs": "${attrs}",
},
body: JSON.stringify(payload),
})
const data = await response.json();
if (!response.ok) {
throw new Error(data);
}
Update Comment Status
- Curl
- Typescript
curl -X PATCH "${baseUrl}/comment/${id}/status/" \
-H "Authorization: Bearer ${accessToken}" \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d @comment.json
info
comment.json
{
"status": 0
}
const response = await fetch("${baseUrl}/comment/${id}/status/", {
method: "PUT",
headers: {
"Content-Type": "application/json",
"Accept": "application/json",
"Authorization": `Bearer ${accessToken}`,
},
body: JSON.stringify(payload),
})
const data = await response.json();
if (!response.ok) {
throw new Error(data);
}
Destroy Comment
- Curl
- Typescript
curl -X DELETE "${baseUrl}/comment/${id}" \
-H "Authorization: Bearer ${accessToken}" \
-H "Content-Type: application/json" \
-H "Accept: application/json"
const response = await fetch("${baseUrl}/comment/${id}", {
method: "DELETE",
headers: {
"Content-Type": "application/json",
"Accept": "application/json",
"Authorization": `Bearer ${accessToken}`,
},
})
const data = await response.json();
if (!response.ok) {
throw new Error(data);
}