Category
Definition
- JSON
- Typescript
category.json
{
"id": 0,
"ref": 0,
"categoryName": "",
"status": 0,
"createdAt": "",
"updatedAt": "",
}
category.ts
export interface ICategory {
id: number;
ref: number;
categoryName: string;
status: number;
createdAt: Date | null;
updatedAt: Date | null;
}
Get Categories
- Curl
- Typescript
curl -X GET "${baseUrl}/category/?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}/category/?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 Category
- Curl
- Typescript
curl -X GET "${baseUrl}/category/${id}" \
-H "Authorization: Bearer ${accessToken}" \
-H "Content-Type: application/json" \
-H "Accept: application/json"
const response = await fetch("${baseUrl}/category/${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 Category.ID
- Curl
- Typescript
curl -X POST "${baseUrl}/apply/category/id/" \
-H "Authorization: Bearer ${accessToken}" \
-H "Content-Type: application/json" \
-H "Accept: application/json"
const response = await fetch("${baseUrl}/apply/category/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 Category
- Curl
- Typescript
curl -X POST "${baseUrl}/category/" \
-H "Authorization: Bearer ${accessToken}" \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d @category.json
info
category.json
{
"ref": 0,
"categoryName": "",
"status": 0,
}
tip
success status: 201
const response = await fetch("${baseUrl}/category/", {
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 Category
- Curl
- Typescript
#!/bin/bash
curl -X PUT "${baseUrl}/category/${id}" \
-H "Authorization: Bearer ${accessToken}" \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d @category.json
info
category.json
{
"ref": 0,
"categoryName": "",
"status": 0,
}
const response = await fetch("${baseUrl}/category/${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 Category
- Curl
- Typescript
curl -X PATCH "${baseUrl}/category/${id}" \
-H "Authorization: Bearer ${accessToken}" \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-H "Attrs: ref,categoryName,status" \
-d @category.json
info
category.json
{
"ref": 0,
"categoryName": "",
"status": 0,
}
const response = await fetch("${baseUrl}/category/${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 Category Status
- Curl
- Typescript
curl -X PATCH "${baseUrl}/category/${id}/status/" \
-H "Authorization: Bearer ${accessToken}" \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d @category.json
info
category.json
{
"status": 0
}
const response = await fetch("${baseUrl}/category/${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 Category
- Curl
- Typescript
curl -X DELETE "${baseUrl}/category/${id}" \
-H "Authorization: Bearer ${accessToken}" \
-H "Content-Type: application/json" \
-H "Accept: application/json"
const response = await fetch("${baseUrl}/category/${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);
}