Skip to content

INDEX#

Keywords#

Glossary#

  • Serialization (์ง๋ ฌํ™”)
    • ๋ณต์žกํ•œ ๋ฐ์ดํ„ฐํƒ€์ž… (์ฟผ๋ฆฌ์…‹, ๋ชจ๋ธ ๊ฐ์ฒด)์„ ๋จผ์ € ํŒŒ์ด์ฌ ๋‚ด์žฅ dict๋กœ ๋ณ€ํ™˜ํ•˜๋Š” ์ผ์„ ๋งํ•œ๋‹ค. ์ด๋ ‡๊ฒŒ ํ•˜๋Š” ์ด์œ ๋Š” dict๋Š” JSON์ด๋‚˜ XML๊ณผ ๊ฐ™์€ ํ˜•์‹์„ ์ค€์ˆ˜ํ•˜๊ธฐ ์‰ฝ๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค.
  • Deserialization (์—ญ์ง๋ ฌํ™”)
    • ๋ฐ˜๋Œ€๋กœ, dict๋กœ ํŒŒ์‹ฑ์ด ๋œ JSON์ด๋‚˜ XML์„ ๋ฐ›์•„ ๋‹ค์‹œ ๋ณต์žกํ•œ ๋ฐ์ดํ„ฐํƒ€์ž…์œผ๋กœ ๋ณ€ํ™˜ํ•˜๋Š” ์ผ์„ ๋งก๋Š”๋‹ค.

Workflow#

  • Form ํด๋ž˜์Šค๋ฅผ ๋งŒ๋“ค๋“ฏ์ด, Serializer๋ฅผ ์ƒ์†๋ฐ›์€ ํด๋ž˜์Šค๋“ค์€ ์ž๊ธฐ๋งŒ์˜ ํ•„๋“œ๋ฅผ ๊ฐ€์งˆ ์ˆ˜ ์žˆ๋‹ค. ํ•„๋“œ๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ (์—ญ)์ง๋ ฌํ™”๊ฐ€ ์ง„ํ–‰์ด ๋˜๋ฉฐ, ๊ธฐ๋Šฅ์„ ๋ช‡๊ฐ€์ง€๋งŒ ์ถ”๊ฐ€ํ•˜๋ฉด view์—์„œ๋Š” ์ด Serializer ๋ฉ”์„œ๋“œ๋ฅผ ํ˜ธ์ถœํ•˜๊ธฐ๋งŒ ํ•˜๋ฉด CRUD๊ฐ€ ๋‹ค ๋œ๋‹ค.
  • create, update ๋“ฑ์„ ์˜ค๋ฒ„๋ผ์ด๋“œํ•˜์—ฌ Serializer ๊ฐ์ฒด์˜ ์ƒํƒœ๋ฅผ ์‹ค์ œ ๋ชจ๋ธ์— ์ ์šฉ์‹œํ‚ฌ ์ˆ˜ ์žˆ๋‹ค. ์ด๋ฆ„์ฒ˜๋Ÿผ, ์ƒˆ๋กœ์šด ๋ ˆ์ฝ”๋“œ๋ฅผ ์ถ”๊ฐ€ํ•  ์ˆ˜๋„ ์žˆ๊ณ , ๊ธฐ์กด์˜ ์ธ์Šคํ„ด์Šค๋ฅผ ์ˆ˜์ •ํ•  ์ˆ˜๋„ ์žˆ๋‹ค.
  • ์—ญ์ง๋ ฌํ™”์‹œ, ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ๋„ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ๋‹ค. ๊ธฐ๋ณธ์ ์œผ๋กœ Form๊ณผ ๋น„์Šทํ•œ ์„ฑ๊ฒฉ์„ ๋งŽ์ด ๋„๊ณ  ์žˆ๊ธฐ ๋•Œ๋ฌธ์— is_valid๋ผ๋Š” ๋ฉ”์„œ๋“œ๋ฅผ ํ†ตํ•ด ํ•„๋“œ์— ์ ๊ฒฉํ•œ ๋ฐ์ดํ„ฐ๊ฐ€ ๋“ค์–ด์™”๋Š”์ง€๋ฅผ ๋ฏธ๋ฆฌ ์•Œ์•„๋‚ผ ์ˆ˜ ์žˆ๋‹ค.
    • ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ๋Š” ๋ณธ์งˆ์ ์œผ๋กœ ํ•„๋“œ์— ๋Œ€ํ•œ ๊ฒ€์‚ฌ์ด๋‹ค. ๋”ฐ๋ผ์„œ ํ•„๋“œ์— ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•œ ๊ฒฝ์šฐ, ์ด๋ฅผ dict์˜ ํ˜•ํƒœ๋กœ ์—๋Ÿฌ ์›์ธ์„ ์•Œ๋ ค์ฃผ๊ฒŒ ๋˜๋Š”๋ฐ, key์—๋Š” ํ•„๋“œ์˜ ์ด๋ฆ„์ด, value์—๋Š” ๊ตฌ์ฒด์ ์ธ ์—๋Ÿฌ ๋ฉ”์‹œ์ง€๊ฐ€ ๋“ค์–ด์˜ค๊ฒŒ ๋œ๋‹ค.
  • Serializer๋Š” ๋‹ค์–‘ํ•œ ์˜ˆ์™ธํด๋ž˜์Šค๋„ ๊ฐ€์ง€๊ณ  ์žˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด ValidationError๋Š” ๋ฐœ์ƒ ์‹œ 400 ์‘๋‹ต์„ ๋ฆฌํ„ดํ•œ๋‹ค.
  • Serializer.save ๋ฉ”์„œ๋“œ๋Š” Model.save์™€๋Š” ์ „ํ˜€ ๋‹ค๋ฅด๋‹ค. ๊ฐ์ฒด ์ธ์Šคํ„ด์Šค๋ฅผ ๋ฆฌํ„ดํ•˜๋Š” ๊ฒƒ์ด์ง€, ๋ชจ๋ธ์— ์ ์šฉํ•˜๋Š” ๋ช…๋ น์ด ์•„๋‹ˆ๋ผ๋Š” ๊ฒƒ์ด๋‹ค. ์™œ ์ด๋”ฐ์œ„๋กœ ๋งŒ๋“ค์—ˆ์ง€ save, create, update์˜ ์ฐจ์ด์  {sof}

GET

sequenceDiagram
    participant Client
    participant Router
    participant View
    participant DB
    participant Serializer
    participant Response

    Client->>Router: GET ์š”์ฒญ
    Router->>View: get ๋ฉ”์„œ๋“œ ํ˜ธ์ถœ
    View->>DB: QuerySet ์š”์ฒญ (ํ•„ํ„ฐ๋ง, ์ •๋ ฌ ๋“ฑ)
    DB->>View: QuerySet ๋ฐ˜ํ™˜
    View->>Serializer: QuerySet ์ „๋‹ฌํ•˜์—ฌ ์ง๋ ฌํ™”
    Serializer-->>View: JSON ๋ฐ์ดํ„ฐ ์ƒ์„ฑ
    View->>Response: Response ๊ฐ์ฒด ์ƒ์„ฑ
    Response-->>Client: ์ง๋ ฌํ™”๋œ JSON ๋ฐ์ดํ„ฐ ๋ฐ˜ํ™˜

POST

sequenceDiagram
    participant Client
    participant Router
    participant View
    participant Serializer
    participant DB
    participant Response

    Client->>Router: HTTP POST
    Router->>View: post ๋ฉ”์„œ๋“œ ํ˜ธ์ถœ
    View->>Serializer: ์š”์ฒญ ๋ฐ์ดํ„ฐ ์—ญ์ง๋ ฌํ™”
    Serializer->>Serializer: is_valid ์‹คํ–‰ (์œ ํšจ์„ฑ ๊ฒ€์‚ฌ)
    Serializer-->>View: ์œ ํšจ์„ฑ ํ™•์ธ ๊ฒฐ๊ณผ ๋ฐ˜ํ™˜
    View->>Serializer: save ํ˜ธ์ถœ
    Serializer->>DB: create ๋˜๋Š” update ์‹คํ–‰
    DB-->>Serializer: ์ €์žฅ๋œ ๊ฐ์ฒด ๋ฐ˜ํ™˜
    Serializer-->>View: ์ €์žฅ๋œ ๊ฐ์ฒด๋ฅผ ๋‹ค์‹œ ์ง๋ ฌํ™”
    View->>Response: Response ๊ฐ์ฒด ์ƒ์„ฑ
    Response-->>Client: ์ง๋ ฌํ™”๋œ JSON ๋ฐ์ดํ„ฐ ๋ฐ˜ํ™˜