File size: 5,254 Bytes
2c1dae0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
# API λͺ…μ„Έμ„œ (v1)

Base URL
```

/api/v1

```

μš”μ•½
- μ£Όμš” λ¦¬μ†ŒμŠ€: /posts, /predict, /uploads, /stats
- 응닡 포맷: JSON (HTML νŽ˜μ΄μ§€λŠ” μ›Ή 라우트둜 별도 제곡)
- ν•„λ“œ 넀이밍: snake_case

- λ‚ μ§œ/μ‹œκ°„: ISO 8601 (예: 2026-04-28T12:34:56Z)



곡톡 μ—λŸ¬ 응닡 (μ˜ˆμ‹œ)

```json

{

  "success": false,

  "error": {

    "code": 400,

    "message": "Bad Request",

    "details": null

  }

}

```



인증 / Rate limiting

- 인증: 선택(예: JWT Authorization: Bearer <token>), ν•„μš”ν•œ μ—”λ“œν¬μΈνŠΈμ— ν‘œκΈ°

- Rate limit: μ˜ˆμ‹œ - 60 requests/min (λ¬Έμ„œν™” ꢌμž₯)



λͺ¨λΈ 메타데이터(ꢌμž₯ 응닡 ν•„λ“œ)

- model_name, model_version, inference_time_ms



---



## 1. μ›Ή νŽ˜μ΄μ§€ λΌμš°νŒ… (HTML)

(μ›Ή μ„œλ²„ ν…œν”Œλ¦Ώμš©; API Base URL 적용 μ—†μŒ)

- GET / β†’ 200 HTML (index.html)

- GET /board β†’ 200 HTML (board.html)

- GET /posts/{post_id} β†’ 200 HTML (post detail)

---

## 2. 이미지 λΆ„λ₯˜ API (routers/predict.py)

### [POST] 이미지 λΆ„λ₯˜
POST /api/v1/predict
Headers:
- Content-Type: multipart/form-data
Request (form-data):
- file: (required) image file, field name `file` (max 10MB, allowed: .jpg, .jpeg, .png)
Response 200:
```json

{

  "success": true,

  "filename": "cat.jpg",

  "predicted_class": "cat",

  "confidence": 0.9821,

  "top_k": [

    {"label":"cat","score":0.9821},

    {"label":"dog","score":0.0121}

  ],

  "model": {

    "name": "classifier",

    "version": "v1.0.0"

  },

  "inference_time_ms": 123

}

```
Errors:
- 400: missing file / invalid file type
- 413: payload too large
- 500: model inference failure

---

### [POST] 이미지 μ—…λ‘œλ“œ + λΆ„λ₯˜ + κ²Œμ‹œκΈ€ μžλ™ 생성
POST /api/v1/predict/upload
Headers:
- Content-Type: multipart/form-data
Request (form-data):
- title: string (required)
- content: string (optional)
- image: file (required) field name `image`
Response 201:
```json

{

  "success": true,

  "post_id": 15,

  "prediction": "cat",

  "confidence": 0.98,

  "model": {"name":"classifier","version":"v1.0.0"}

}

```

---

### [GET] λͺ¨λΈ 라벨 λͺ©λ‘
GET /api/v1/predict/labels
Response 200:
```json

{

  "classes": ["cat","dog","car","person"]

}

```

---

## 3. κ²Œμ‹œκΈ€ API (routers/post.py)

### [GET] κ²Œμ‹œκΈ€ λͺ©λ‘ (νŽ˜μ΄μ§•/ν•„ν„°)
GET /api/v1/posts
Query params:
- page: int (default 1)
- size: int (default 10)
- category: string (optional)
Response 200:
```json

{

  "items": [

    {

      "id": 1,

      "title": "고양이 λΆ„λ₯˜ 성곡",

      "prediction": "cat",

      "confidence": 0.98,

      "created_at": "2026-04-28T12:00:00Z"

    }

  ],

  "page": 1,

  "size": 10,

  "total": 34

}

```

### [GET] κ²Œμ‹œκΈ€ 상세
GET /api/v1/posts/{id}
Response 200:
```json

{

  "id": 1,

  "title": "고양이 λΆ„λ₯˜ 성곡",

  "content": "ν…ŒμŠ€νŠΈ κΈ€",

  "image_url": "/uploads/cat.jpg",

  "prediction": "cat",

  "confidence": 0.98,

  "created_at": "2026-04-28T12:00:00Z"

}

```
404: post not found

### [POST] κ²Œμ‹œκΈ€ 생성
POST /api/v1/posts
Headers:
- Content-Type: application/json
Request body:
```json

{

  "title":"μƒˆ κ²Œμ‹œκΈ€",

  "content":"λ‚΄μš©",

  "image_url":"/uploads/sample.jpg",

  "prediction":"cat",

  "confidence":0.95

}

```
Response 201:
```json

{"success": true, "id": 123}

```
Validation: title required, image_url optional, confidence 0.0-1.0



### [PUT] κ²Œμ‹œκΈ€ μˆ˜μ •

PUT /api/v1/posts/{id}

Request body (partial ν—ˆμš©):

```json

{"title":"μˆ˜μ • 제λͺ©","content":"μˆ˜μ • λ‚΄μš©"}

```

Response 200: {"success": true}



### [DELETE] κ²Œμ‹œκΈ€ μ‚­μ œ

DELETE /api/v1/posts/{id}

Response 200:

```json

{"success": true, "message": "μ‚­μ œ μ™„λ£Œ"}

```



---



## 4. μ’‹μ•„μš” / μΆ”μ²œ

POST /api/v1/posts/{id}/like

Response 200:

```json

{"success": true, "likes": 12}

```



---



## 5. 톡계 API (λŒ€μ‹œλ³΄λ“œμš©)

GET /api/v1/stats/classes

Query params (optional):

- start_date, end_date (ISO 8601)

Response 200:

```json

{"cat":34,"dog":20,"car":14}

```



---



## 데이터/응닡 μŠ€ν‚€λ§ˆ (schemas.py)



PostCreate

- title: string (required)

- content: string (optional)

- image_url: string (optional, 경둜)
- prediction: string (optional)
- confidence: float (0.0 - 1.0, optional)

PostResponse
- id: int
- title: string
- content: string
- image_url: string

- prediction: string

- confidence: float

- created_at: datetime (ISO 8601)

PredictResponse
- success: bool
- filename: string
- predicted_class: string

- confidence: float

- top_k: [{label: string, score: float}]
- model: {name:string, version:string}
- inference_time_ms: int

ErrorResponse
- success: false
- error: {code:int, message:string, details:object|null}

---

## κ΅¬ν˜„/운영 ꢌμž₯사항
- λͺ¨λ“  APIλŠ” /api/v1/ 접두사λ₯Ό μ‚¬μš©ν•΄ 버전 관리
- μš”μ²­/응닡 μ˜ˆμ‹œλŠ” OpenAPI(Swagger)둜 μž‘μ„±ν•΄ μžλ™ λ¬Έμ„œν™” ꢌμž₯
- 파일 μ—…λ‘œλ“œλŠ” μ €μž₯μ†Œ μš©λŸ‰, ν™•μž₯자 검사, μ•…μ„± 파일 검사 κ΅¬ν˜„
- λ―Όκ°ν•œ 파일 μ—…λ‘œλ“œλŠ” 인증/ACL 적용
- λͺ¨λΈ 버전 관리 및 A/B ν…ŒμŠ€νŠΈ 둜그 남기기
- μžμ„Έν•œ λ‘œκΉ…(μš”μ²­ id, inference time, model version)으둜 문제 좔적

---