๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๊ฐœ๋ฐœ/Web

[Web] Restful API๋ž€?

by ynzu๐Ÿค 2022. 2. 21.
๋ฐ˜์‘ํ˜•

 

API (Application Programming Interface)

์†Œํ”„ํŠธ์›จ์–ด๊ฐ€ ๋‹ค๋ฅธ ์†Œํ”„ํŠธ์›จ์–ด๋กœ๋ถ€ํ„ฐ ์ง€์ •๋œ ํ˜•์‹์œผ๋กœ ๋ช…๋ น์„ ๋ฐ›์„ ์ˆ˜ ์žˆ๋Š” ์ˆ˜๋‹จ

  • ์ •๋ณด๋ฅผ ์ฃผ๊ณ  ๋ฐ›๋Š” ์ผ์ข…์˜ ํ˜•์‹
  • ์ •๋ณด๋ฅผ ์š”์ฒญํ•œ๋Š” ์ง€์ •๋œ ํ˜•์‹์ด ์žˆ์–ด์•ผ ํ•จ

 

Restful API

  • ๊ณผ๊ฑฐ์˜ SOAP๋ผ๋Š” ๋ณต์žกํ•œ ํ˜•์‹ ๋Œ€์ฒด
  • ๊ฐ€์žฅ ์ค‘์š”ํ•œ ํŠน์„ฑ์€ ๊ฐ ์š”์ฒญ์ด ์–ด๋–ค ๋™์ž‘์ด๋‚˜ ์ •๋ณด๋ฅผ ์œ„ํ•œ ๊ฒƒ์ธ์ง€ ๊ทธ ์š”์ฒญ์˜ ๋ชจ์Šต ์ž์ฒด๋กœ ์ถ”๋ก ์ด ๊ฐ€๋Šฅํ•ด์•ผ ํ•จ

 


 

URL๋งŒ ๋ด๋„ ์–ด๋–ค ์š”์ฒญ์„ ํ•˜๊ธฐ ์œ„ํ•จ์ธ์ง€ ํŒŒ์•…ํ•  ์ˆ˜ ์žˆ์–ด์•ผ ํ•จ!

- 'https://domain/1, https://domain/hello ' : ๋ฌด์Šจ ๊ธฐ๋Šฅ์ธ์ง€ ๋ช…ํ™•ํžˆ ํŒŒ์•…ํ•˜๊ธฐ ์–ด๋ ค์›€ 

- https://๋„๋ฉ”์ธ/classes :  class ๋ชฉ๋ก์„ ๋ฐ›์•„์˜ค๋Š” ์š”์ฒญ์ด๋ผ๋Š” ๊ฒƒ์„ ํŒŒ์•…ํ•  ์ˆ˜ ์žˆ์Œ

{
	"result":[
			{"idx":1, "name":"์ˆ˜ํ•™๋ฐ˜"},
			{"idx":2, "name":"์˜์–ด๋ฐ˜"},
			{"idx":3, "name":"๊ตญ์–ด๋ฐ˜"},
			{"idx":4, "name":"๊ณผํ•™๋ฐ˜"},
	]
}

- https://๋„๋ฉ”์ธ/classes/2 : inx๊ฐ€ 2์ธ class๋ฅผ ๋ฐ›์•„์˜ค๋Š” ์š”์ฒญ์ด๋ผ๋Š” ๊ฒƒ์„ ํŒŒ์•…ํ•  ์ˆ˜ ์žˆ์Œ

{"idx":2, "name":"์˜์–ด๋ฐ˜"}

- https://๋„๋ฉ”์ธ/classes/2/student : 2๋ฐ˜์— ํ•ด๋‹นํ•˜๋Š” ํ•™์ƒ๋“ค์˜ ์ •๋ณด๋ฅผ ์š”์ฒญํ•˜๋Š” ๊ฒƒ์„ ํŒŒ์•…ํ•  ์ˆ˜ ์žˆ์Œ

{
	"result":[
			{"idx":1, "name":"ํ™๊ธธ๋™1"},
			{"idx":2, "name":"ํ™๊ธธ๋™2"},
			{"idx":3, "name":"ํ™๊ธธ๋™3"},
			{"idx":4, "name":"ํ™๊ธธ๋™4"},
	]
}

์ด๋ ‡๊ฒŒ URI๋งŒ ๋ด๋„ ๋ฌด์Šจ ๊ธฐ๋Šฅ์ธ์ง€ ํŒŒ์•…ํ•  ์ˆ˜ ์žˆ์–ด์•ผ ํ•จ(์ง๊ด€์ ์ด์—ฌ์•ผ ํ•จ)

 

๋ชฉ์ ์— ๋”ฐ๋ผ  HTTP method๋ฅผ ๊ตฌ๋ถ„ํ•ด์„œ ์‚ฌ์šฉํ•ด์•ผํ•จ

- CRUD ( CREATE, READ, UPDATE, DELETE)

์„œ๋ฒ„์— Rest API ์š”์ฒญ์„ ๋ณด๋‚ผ ๋•Œ HTTP(Hyper Text Transfer Protocol)๋ผ๋Š” ๊ทœ์•ฝ์— ๋”ฐ๋ผ ์ „์†กํ•จ.

post, put, patch : body์— ์ •๋ณด๋ฅผ ๋ณด๋ƒ„(get, delete๋ณด๋‹ค ๋งŽ์€ ์ •๋ณด๋ฅผ ํฌํ•จํ•  ์ˆ˜ ์žˆ์Œ)

 

- ์š”์ฒญ์˜ ์˜๋„๋ฅผ ์‰ฝ๊ฒŒ ํŒŒ์•…ํ•  ์ˆ˜ ์žˆ๋„๋ก HTTP Method๋„ ์ž˜ ์„ ํƒํ•ด์•ผ ํ•จ.

GET : ๋ฐ์ดํ„ฐ ์š”์ฒญ, ์กฐํšŒ

POST : ๋ฐ์ดํ„ฐ ์ถ”๊ฐ€

PUT, PETCH : ๋ฐ์ดํ„ฐ ์ˆ˜์ • (PUT : ์ „์ฒด ์ •๋ณด ์ˆ˜์ •, PETCH : ์ผ๋ถ€ ์ˆ˜์ •)

DELETE : ๋ฐ์ดํ„ฐ ์‚ญ์ œ

 

ํ˜•์‹์ด๊ธฐ ๋•Œ๋ฌธ์— ๊ธฐ์ˆ (์–ธ์–ด)์— ๊ตฌ์• ๋ฐ›์ง€๋Š” ์•Š์ง€๋งŒ ์•ฝ์†๋œ ๋Œ€๋กœ, ์ •์„ ๋Œ€๋กœ ํ•ด์•ผํ•˜๋ฉฐ, URI๋Š” ๋ช…์‚ฌ๋กœ ํ•˜์ž(๋™์‚ฌX)

 

 

728x90
๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€