Mozzida
article thumbnail

1. ๐Ÿ”HTTP ์š”์ฒญ ๋ฐฉ์‹

  • HTTP ํ†ต์‹  : ์•ฝ์†
  • ํ†ต์‹  ๋ฐฉ๋ฒ• 4๊ฐ€์ง€ : GET, POST, PUT, DELETE (์ด์™ธ์—๋„ ๋” ๋งŽ์ง€๋งŒ ์ด 4๊ฐ€์ง€๋งŒ ๊ธฐ์–ตํ•˜๋ฉด ๋œ๋‹ค๊ณ  ํ•˜์…จ๋‹ค.)
  • GET : ๋ฐ์ดํ„ฐ๋ฅผ ์ค˜! -Select
  • POST : ๋ฐ์ดํ„ฐ๋ฅผ ์ถ”๊ฐ€ํ•ด์ค˜! -Insert
  • PUT : ๋ฐ์ดํ„ฐ๋ฅผ ์ˆ˜์ •ํ•ด์ค˜! -Update
  • DELETE : ๋ฐ์ดํ„ฐ๋ฅผ ์‚ญ์ œํ•ด์ค˜! -Delete

 

2. ๐Ÿ”MIME (Multipurpose Internet Mail Extensions) ์ด๋ž€?

  • ๋‹ค๋ชฉ์  ์ธํ„ฐ๋„ท ๋ฉ”์ผ ํ™•์žฅ์ด๋ž€ ๋œป์œผ๋กœ ์ „์ž์šฐํŽธ์˜ ๋ฐ์ดํ„ฐ ํ˜•์‹์„ ์ •์˜ํ•œ ํ‘œ์ค€ ํฌ๋งท
  • ๊ธฐ์กด ์ „์ž์šฐํŽธ์€ ๋ฌธ์ž ๋ฐ์ดํ„ฐ ์ด์™ธ์˜ ๋ฐ”์ด๋„ˆ๋ฆฌ ๋ฐ์ดํ„ฐ(์ด๋ฏธ์ง€, ๋™์˜์ƒ, MS ์›Œ๋“œ ๋“ฑ)๋ฅผ ์ „์†กํ•  ์ˆ˜ ์—†์—ˆ๋‹ค.
  • ๊ทธ๋ฆฌํ•˜์—ฌ ์—ฌ๋Ÿฌ ๋ฉ€ํ‹ฐ๋ฏธ๋””์–ด ๋ฐ์ดํ„ฐ๋“ค์˜ ๋ฐ”์ด๋„ˆ๋ฆฌ ๋ฐ์ดํ„ฐ๋ฅผ ASCII ์ฝ”๋“œ๋กœ ๋ณ€ํ™˜ํ•˜๋Š” ๋ฐฉ๋ฒ•(์ธ์ฝ”๋”ฉ)๊ณผ ๋ฏธ๋””์–ด ์ข…๋ฅ˜๋ฅผ MIME ํƒ€์ž…์œผ๋กœ ์ •์˜ ํ›„, MIME ์‚ฌ์–‘์— ๋”ฐ๋ผ ๋ฉ€ํ‹ฐ๋ฏธ๋””์–ด ํŒŒ์ผ์˜ ๋ฐ์ดํ„ฐ๋ฅผ ASCII ๋ฐ์ดํ„ฐ๋กœ ๋ณ€ํ™˜ ํ›„ ์ „์†กํ•  ์ˆ˜ ์žˆ๊ฒŒ๋จ.

 

3. ๐Ÿ”MIME ํƒ€์ž…

  • text : ํ…์ŠคํŠธ๋ฅผ ํ‘œํ˜„ (text/plain, text/html, text/css, text/javascript)
  • image : ์ด๋ฏธ์ง€๋ฅผ ํ‘œํ˜„
  • video : ๋™์˜์ƒ์„ ํ‘œํ˜„
  • application : ๋ชจ๋“  ์ข…๋ฅ˜์˜ ์ด์ง„ ๋ฐ์ดํ„ฐ๋ฅผ ํ‘œํ˜„
  • multipart : ์—ฌ๋Ÿฌ ๊ฐ€์ง€ ํƒ€์ž…์˜ ๋ฐ์ดํ„ฐ๋“ค์„ ๋™์‹œ์— ์ „์†กํ•  ๋•Œ ์‚ฌ์šฉ

4. ๐ŸคPostMan ์‚ฌ์šฉํ•˜์—ฌ HTTP ์š”์ฒญ ์‹ค์Šตํ•˜๊ธฐ

๋จผ์ € Postman ์„ ์„ค์น˜ํ•ด ์ค€๋‹ค.

ํฌ๋กฌ์—๋„ ์„ค์น˜ํ•ด ์ค€๋‹ค.

 

๊ทธ๋ฆฌ๊ณ  ์•„์ง ๋””๋น„์— ํ…Œ์ด๋ธ”์„ ์ƒ์„ฑํ•˜์ง€ ์•Š์•˜์ง€๋งŒ ์‹ค์Šต์šฉ ๋ชจ๋ธ์ธ Member.java ํŒŒ์ผ์„ ๋งŒ๋“ค์–ด์ค€๋‹ค.

<java />
public class Member { private int id; private String username; private String password; private String email; public Member(int id, String username, String password, String email) { this.id = id; this.username = username; this.password = password; this.email = email; } public int getId() { return id; } public void setId(int id) { this.id = id; } public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } }

 

HttpController.java ํŒŒ์ผ์„ ์ƒ์„ฑํ•ด ์ค€๋‹ค.

<java />
import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; //์‚ฌ์šฉ์ž๊ฐ€ ์š”์ฒญ -> ์‘๋‹ต(Data)์„ ํ•ด์ฃผ๋Š” ์—ญํ•  @RestController public class HttpController { //http://localhost:8080/http/get (select) //์ธํ„ฐ๋„ท ๋ธŒ๋ผ์šฐ์ € ์š”์ฒญ์€ ๋ฌด์กฐ๊ฑด get ์š”์ฒญ๋ฐ–์— ํ•  ์ˆ˜ ์—†๋‹ค. @GetMapping("/http/get") public String getTest() { return "get ์š”์ฒญ"; } //http://localhost:8080/http/post (insert) @PostMapping("/http/post") public String postTest() { //MessageConverter(์Šคํ”„๋ง๋ถ€ํŠธ) return "post ์š”์ฒญ"; } //http://localhost:8080/http/put (update) @PutMapping("/http/put") public String putTest() { return "put ์š”์ฒญ "; } //http://localhost:8080/http/delete (delete) @DeleteMapping("/http/delete") public String deleteTest() { return "delete ์š”์ฒญ"; } }

 

ํ”„๋กœ์ ํŠธ ์‹คํ–‰ ํ›„ ๋จผ์ € Get๋งคํ•‘ํ•ด๋‘” ์ฃผ์†Œ๋ฅผ ์ž…๋ ฅํ•˜๋ฉด ์•„๋ž˜์™€ ๊ฐ™์ด ์ž˜ ๋‚˜์˜จ๋‹ค. ๊ทธ๋Ÿฌ๋‚˜

 

Post๋งคํ•‘ํ•ด๋‘” ์ฃผ์†Œ ์ž…๋ ฅ ์‹œ์—๋Š” ์—๋Ÿฌ๊ฐ€ ๋‚œ๋‹ค. -> ์ธํ„ฐ๋„ท ๋ธŒ๋ผ์šฐ์ € ์š”์ฒญ์€ ๋ฌด์กฐ๊ฑด get ์š”์ฒญ๋ฐ–์— ํ•  ์ˆ˜ ์—†๋‹ค.

๊ทธ๋ ‡๊ธฐ ๋•Œ๋ฌธ์— ์šฐ๋ฆฌ๋Š” Postman์„ ์‚ฌ์šฉํ•  ๊ฒƒ์ด๋‹ค.

 

Postman์„ ์ผœ์„œ ๊ฐ๊ฐ ๋งคํ•‘ํ•ด๋‘” ์ฃผ์†Œ๋ฅผ ์ž…๋ ฅํ•˜๋ฉด ์•Œ๋งž๊ฒŒ ๋‚˜์˜จ๋‹ค.

 

  • Post

 

 

  • Put

 

  • Get

 

  • Delete

 

์ด๋•Œ ๋ฏธ๋ฆฌ ๋งŒ๋“ค์–ด๋†“์€ member ํด๋ž˜์Šค๋ฅผ ํ™œ์šฉํ•˜์—ฌ HTTP ์š”์ฒญ์„ ํ™•์ธํ•ด๋ณผ ์ˆ˜ ์žˆ๋‹ค. ๋จผ์ € ์•„๋ž˜์™€ ๊ฐ™์ด getTest ๋ฉ”์„œ๋“œ๋ฅผ ์ˆ˜์ • ํ›„ postman์—์„œ get ์š”์ฒญ์„ ํ•ด๋ณด๋ฉด

 

์ด๋ ‡๊ฒŒ id ๊ฐ’์ด ํ•จ๊ป˜ ๋‚˜์˜จ๋‹ค. ์ด๋•Œ http/get?id=1 ์ด ๋ถ€๋ถ„์„ ์ฟผ๋ฆฌ์ŠคํŠธ๋ง์ด๋ผ๊ณ  ํ•œ๋‹ค.

 

Post ์š”์ฒญ๋„ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ

 

text ๊ฐ’์ด ์ž˜ ๋‚˜์˜จ๋‹ค. ์ด๋•Œ raw ๋ถ€๋ถ„์˜ Text์— ์œ„์—์„œ ์„ค๋ช…ํ–ˆ๋˜ MIME ํƒ€์ž…(text/plain) ์ด ์‚ฌ์šฉ๋œ ๊ฒƒ์ด๋‹ค.

 

์•„๋ž˜์™€ ๊ฐ™์ด ์ฝ”๋“œ๋ฅผ ๋ฐ”๊พธ๊ณ 

 

text/plain -> application/json ํƒ€์ž…์œผ๋กœ ์š”์ฒญ์„ ํ•  ๋•Œ์—๋Š” ์•„๋ž˜์™€ ๊ฐ™์ด {} ์•ˆ์— ๋ฐ์ดํ„ฐ๋ฅผ ๋‹ด์•„์„œ ์ „์†กํ•œ๋‹ค. ์ด๋•Œ ์™ผ์ชฝ ๊ฐ’์„ key๋ผ๊ณ  ํ•˜๊ณ  key๊ฐ’์€ ํ•ญ์ƒ String ํƒ€์ž…์ด๊ธฐ ๋•Œ๋ฌธ์— ์Œ๋”ฐ์˜ดํ‘œ๋กœ ๋ฌถ์–ด์ค˜์•ผ ํ•œ๋‹ค. ์˜ค๋ฅธ์ชฝ์—๋Š” ์ˆซ์ž๊ฐ€ ์˜ฌ ์ˆ˜๋„ ์žˆ๊ณ  ๋ฌธ์ž๊ฐ€ ์˜ฌ ์ˆ˜๋„ ์žˆ๊ณ  ๋‹ค์–‘ํ•œ ๊ฐ’์ด ์˜ฌ ์ˆ˜ ์žˆ๋‹ค.

Put๋งคํ•‘์œผ๋กœ ์š”์ฒญ ์‹œ์—๋„

 

๊ฐ’์ด ์ž˜ ์ถœ๋ ฅ๋œ๋‹ค. emailํ•˜๊ณ  name์€ ์œ„ ์ฝ”๋“œ์—์„œ ๋„˜๊ธฐ์ง€ ์•Š์•˜๊ธฐ ๋•Œ๋ฌธ์— ๋‹น์—ฐํžˆ null๊ฐ’์œผ๋กœ ๋‚˜์˜จ๋‹ค.

 

profile

Mozzida

@Mozzida

ํฌ์ŠคํŒ…์ด ์ข‹์•˜๋‹ค๋ฉด "์ข‹์•„์š”โค๏ธ" ๋˜๋Š” "๊ตฌ๋…๐Ÿ‘๐Ÿป" ํ•ด์ฃผ์„ธ์š”!