Article
Definition
- JSON
- Typescript
article.json
{
"id": 0,
"categoryID": 0,
"userID": 0,
"key": "",
"articleTitle": "",
"articleContent": "",
"status": 0,
"createdAt": "",
"updatedAt": "",
}
article.ts
export interface IArticle {
id: number;
categoryID: number;
userID: number;
key: string;
articleTitle: string;
articleContent: string;
status: number;
createdAt: Date | null;
updatedAt: Date | null;
}
Get Articles
- Curl
- Typescript
curl -X GET "${baseUrl}/article/?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}/article/?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 Article
- Curl
- Typescript
curl -X GET "${baseUrl}/article/${id}" \
-H "Authorization: Bearer ${accessToken}" \
-H "Content-Type: application/json" \
-H "Accept: application/json"
const response = await fetch("${baseUrl}/article/${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 Article.ID
- Curl
- Typescript
curl -X POST "${baseUrl}/apply/article/id/" \
-H "Authorization: Bearer ${accessToken}" \
-H "Content-Type: application/json" \
-H "Accept: application/json"
const response = await fetch("${baseUrl}/apply/article/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 Article
- Curl
- Typescript
curl -X POST "${baseUrl}/article/" \
-H "Authorization: Bearer ${accessToken}" \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d @article.json
info
article.json
{
"categoryID": 0,
"userID": 0,
"key": "",
"articleTitle": "",
"articleContent": "",
"status": 0,
}
tip
success status: 201
const response = await fetch("${baseUrl}/article/", {
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 Article
- Curl
- Typescript
#!/bin/bash
curl -X PUT "${baseUrl}/article/${id}" \
-H "Authorization: Bearer ${accessToken}" \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d @article.json
info
article.json
{
"categoryID": 0,
"userID": 0,
"key": "",
"articleTitle": "",
"articleContent": "",
"status": 0,
}
const response = await fetch("${baseUrl}/article/${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 Article
- Curl
- Typescript
curl -X PATCH "${baseUrl}/article/${id}" \
-H "Authorization: Bearer ${accessToken}" \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-H "Attrs: categoryID,userID,key,articleTitle,articleContent,status" \
-d @article.json
info
article.json
{
"categoryID": 0,
"userID": 0,
"key": "",
"articleTitle": "",
"articleContent": "",
"status": 0,
}
const response = await fetch("${baseUrl}/article/${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 Article Status
- Curl
- Typescript
curl -X PATCH "${baseUrl}/article/${id}/status/" \
-H "Authorization: Bearer ${accessToken}" \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d @article.json
info
article.json
{
"status": 0
}
const response = await fetch("${baseUrl}/article/${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 Article
- Curl
- Typescript
curl -X DELETE "${baseUrl}/article/${id}" \
-H "Authorization: Bearer ${accessToken}" \
-H "Content-Type: application/json" \
-H "Accept: application/json"
const response = await fetch("${baseUrl}/article/${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);
}
Get Tags
- Curl
- Typescript
curl -X GET "${baseUrl}/article/${id}/tag/?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}/article/${id}/tag/?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);
}
Link Tags
- Curl
- Typescript
curl -X POST "${baseUrl}/article/${id}/tag/" \
-H "Authorization: Bearer ${accessToken}" \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d "[1,2,3,4]"
const response = await fetch("${baseUrl}/article/${id}/tag/", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Accept": "application/json",
"Authorization": `Bearer ${accessToken}`,
},
body: "[1,2,3,4]",
})
const data = await response.json();
if (!response.ok) {
throw new Error(data);
}
UnLink Tags
- Curl
- Typescript
curl -X DELETE "${baseUrl}/article/${id}/tag/" \
-H "Authorization: Bearer ${accessToken}" \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d "[1,2,3,4]"
const response = await fetch("${baseUrl}/article/${id}/tag/", {
method: "DELETE",
headers: {
"Content-Type": "application/json",
"Accept": "application/json",
"Authorization": `Bearer ${accessToken}`,
},
body: "[1,2,3,4]",
})
const data = await response.json();
if (!response.ok) {
throw new Error(data);
}