๐ ํ ์ผ(Todo) ๊ด๋ฆฌ ์ฑ
์ฃผ์ด์ง API๋ฅผ ํ์ฉํด ‘์์ฑ ์์‘ ์ฒ๋ผ ํ ์ผ(Todo) ๊ด๋ฆฌ ๊ธฐ๋ฅ์ ๊ตฌํํฉ๋๋ค. Vue Composition API + TypeScript๋ฅผ ์ฌ์ฉํด ๊ตฌํํฉ๋๋ค.
API ์ ๋ณด
๋ชจ๋ ์์ฒญ์ ๋ค์ Headers ์ ๋ณด๊ฐ ํ์๋ก ํฌํจ๋ผ์ผ ํฉ๋๋ค.
<APIKEY>
์ <USERNAME>
์ ๋ณด๋ ๋ณ๋ ์ ๊ณตํฉ๋๋ค.
curl <ENDPOINT>
\ -X <METHOD>
\ -H 'content-type: application/json'
\ -H 'apikey: <APIKEY>'
\ -H 'username: <USERNAME>'
- ํ์ฌ ์์ ์์๋ ‘ํ ์ผ ๋ชฉ๋ก ์์ ๋ณ๊ฒฝ’ API์
order
์์ฑ์ ์ฌ์ฉํ์ง ์์์ต๋๋ค.
ํ ์ผ ๋ชฉ๋ก ์กฐํ
์ ์ฒด ํ ์ผ ๋ชฉ๋ก์ ์กฐํํฉ๋๋ค.
curl https://asia-northeast3-heropy-api.cloudfunctions.net/api/todos
\ -X 'GET'
์์ฒญ ๋ฐ์ดํฐ ํ์ ๋ฐ ์์:
- N/A
์๋ต ๋ฐ์ดํฐ ํ์ ๋ฐ ์์:
type ResponseValue = Todo[] // ํ ์ผ ๋ชฉ๋ก
interface Todo {
id: string // ํ ์ผ ID
order: number // ํ ์ผ ์์
title: string // ํ ์ผ ์ ๋ชฉ
done: boolean // ํ ์ผ ์๋ฃ ์ฌ๋ถ
createdAt: string // ํ ์ผ ์์ฑ์ผ
updatedAt: string // ํ ์ผ ์์ ์ผ
}
[
{
"id": "mnIwaAPIAE1ayQmqekiR",
"order": 0,
"title": "JS ๊ณต๋ถํ๊ธฐ",
"done": false,
"createdAt": "2021-10-28T05:18:51.868Z",
"updatedAt": "2021-10-28T05:18:51.868Z"
},
{
"id": "tMzPImGoWtRdJ6yyVv2y",
"order": 1,
"title": "๊ณผ์ PullRequest(PR) ์์ฑ",
"done": true,
"createdAt": "2021-10-28T04:16:53.980Z",
"updatedAt": "2021-10-28T09:40:17.955Z"
},
{
"id": "Rq8BebKihCgteHHhMIRS",
"order": 2,
"title": "API ์คํฐ๋",
"done": false,
"createdAt": "2021-10-28T04:17:02.510Z",
"updatedAt": "2021-10-28T04:17:02.510Z"
}
]
ํ ์ผ ํญ๋ชฉ ์ถ๊ฐ
ํ ์ผ ํญ๋ชฉ์ ์๋กญ๊ฒ ์ถ๊ฐํฉ๋๋ค.
curl https://asia-northeast3-heropy-api.cloudfunctions.net/api/todos
\ -X 'POST'
์์ฒญ ๋ฐ์ดํฐ ํ์ ๋ฐ ์์:
interface RequestBody {
title: string // ํ ์ผ ์ ๋ชฉ
order?: number // ํ ์ผ ์์
}
{
"title": "KDT ๊ณผ์ ์ค๊ณ ๋ฏธํ
"
}
์๋ต ๋ฐ์ดํฐ ํ์ ๋ฐ ์์:
interface ResponseValue {
id: string
order: number
title: string
done: boolean
createdAt: string
updatedAt: string
}
{
"id": "7P8dOM4voAv8a8cfoeKZ",
"order": 0,
"title": "KDT ๊ณผ์ ์ค๊ณ ๋ฏธํ
",
"done": false,
"createdAt": "2021-10-29T07:20:02.749Z",
"updatedAt": "2021-10-29T07:20:02.749Z"
}
ํ ์ผ ํญ๋ชฉ ์์
ํน์ ํ ์ผ ํญ๋ชฉ์ ์์ ํฉ๋๋ค.
curl https://asia-northeast3-heropy-api.cloudfunctions.net/api/todos/:todoId
\ -X 'PUT'
์์ฒญ ๋ฐ์ดํฐ ํ์ ๋ฐ ์์:
interface RequestBody {
title: string // ํ ์ผ ์ ๋ชฉ
done: boolean // ํ ์ผ ์๋ฃ ์ฌ๋ถ
order?: number // ํ ์ผ ์์
}
{
"title": "Bootstrap ์คํ์ผ ์ถ๊ฐ",
"done": false
}
์๋ต ๋ฐ์ดํฐ ํ์ ๋ฐ ์์:
{
"id": "7P8dOM4voAv8a8cfoeKZ",
"title": "Bootstrap ์คํ์ผ ์ถ๊ฐ",
"done": false,
"order": 2,
"createdAt": "2021-10-29T07:20:02.749Z",
"updatedAt": "2021-10-29T07:20:02.749Z"
}
ํ ์ผ ํญ๋ชฉ ์ญ์
ํน์ ํ ์ผ ํญ๋ชฉ์ ์ญ์ ํฉ๋๋ค.
curl https://asia-northeast3-heropy-api.cloudfunctions.net/api/todos/:todoId
\ -X 'DELETE'
์์ฒญ ๋ฐ์ดํฐ ํ์ ๋ฐ ์์:
- N/A
์๋ต ๋ฐ์ดํฐ ํ์ ๋ฐ ์์:
type ResponseValue = true // ์ ์ ์๋ต
ํ ์ผ ํญ๋ชฉ ์ผ๊ด ์ญ์
curl https://asia-northeast3-heropy-api.cloudfunctions.net/api/todos/deletions
\ -X 'DELETE'
์์ฒญ ๋ฐ์ดํฐ ํ์ ๋ฐ ์์:
interface RequestBody {
todoIds: string[] // ์ญ์ ํ ํ ์ผ ID ๋ชฉ๋ก
}
{
"todoIds": [
"mnIwaAPIAE1ayQmqekiR",
"tMzPImGoWtRdJ6yyVv2y",
"GHrvr3LaPx1g7y2sNuaC",
"Rq8BebKihCgteHHhMIRS"
]
}
์๋ต ๋ฐ์ดํฐ ํ์ ๋ฐ ์์:
type ResponseValue = true // ์ ์ ์๋ต
ํ ์ผ ๋ชฉ๋ก ์์ ๋ณ๊ฒฝ
ํ ์ผ ๋ชฉ๋ก์ ์์๋ฅผ ๋ณ๊ฒฝํฉ๋๋ค.
curl https://asia-northeast3-heropy-api.cloudfunctions.net/api/todos/reorder
\ -X 'PUT'
์์ฒญ ๋ฐ์ดํฐ ํ์ ๋ฐ ์์:
interface RequestBody {
todoIds: string[] // ์๋กญ๊ฒ ์ ๋ ฌํ ํ ์ผ ID ๋ชฉ๋ก
}
{
"todoIds": [
"mnIwaAPIAE1ayQmqekiR",
"tMzPImGoWtRdJ6yyVv2y",
"GHrvr3LaPx1g7y2sNuaC",
"Rq8BebKihCgteHHhMIRS"
]
}
์๋ต ๋ฐ์ดํฐ ํ์ ๋ฐ ์์:
type ResponseValue = true // ์ ์ ์๋ต