RESTful API๐Ÿ’ก: URL์— ๋“ค์–ด๊ฐ€๋Š” ํŒŒ๋ผ๋ฏธํ„ฐ ๋„ค์ด๋ฐ

์ •์€๊ฒฝยท2020๋…„ 10์›” 29์ผ
5

๐ŸŽธ Play the Djangoย 

๋ชฉ๋ก ๋ณด๊ธฐ
42/57

์žฅ๊ณ ๋กœ URL query string์„ ๋งŒ๋“œ๋Š”๋ฐ..

query string์— ๋“ค์–ด๊ฐ€๋Š” ํŒŒ๋ผ๋ฏธํ„ฐ์˜ ๋„ค์ด๋ฐ

ํŒŒ์ด์ฌ์—์„œ ํ•จ์ˆ˜/๋ณ€์ˆ˜๊ฐ€ ๋‘๊ฐœ์˜ ๋‹จ์–ด๋กœ ์ด๋ฃจ์–ด์ง€๋Š” ๊ฒฝ์šฐ
์•„๋ž˜์™€ ๊ฐ™์ด, ์Šค๋„ค์ดํฌ๋“œ ๋„ค์ด๋ฐ ๋ฃฐ์— ๋”ฐ๋ฅธ๋‹ค
์˜ˆ) data_kind

๊ทธ๋ ‡๋‹ค๋ฉด ์ฟผ๋ฆฌ ์ŠคํŠธ๋ง ํŒŒ๋ผ๋ฏธํ„ฐ ๋„ค์ด๋ฐ์€ ์–ด๋–ป๊ฒŒ?
์ด ๊ถ๊ธˆ์ฆ ํ•ด๊ฒฐํ•˜๋Ÿฌ ์ฑ…์ฝ์œผ๋Ÿฌ ๊ฐ‘๋‹ˆ๋‹น
API ๋””์ž์ธ๐Ÿงšโ€โ™€๏ธ: REST API Design Rulebook

camalCase๋ฅผ ์“ฐ๋ผ๊ณ  ์ œ์‹œ

"REST API Design Rulebook"(2011๋…„ ์ถœ๊ฐ„)์—์„œ๋Š” camalCase๋ฅผ ์“ฐ๋ผ๊ณ  ๋ช…์‹œ์ ์œผ๋กœ ์–ธ๊ธ‰ํ•œ ๋ฌธ์žฅ์€ ์—†์ง€๋งŒ,
query string ์˜ˆ์ œ์—์„œ camalCase๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ์Œ!
๊ฐ„์ ‘์ ์œผ๋กœ camalCase๋ฅผ ์“ฐ๋Š” ๊ฒƒ์„ ์ œ์•ˆํ•œ๋‹ค๊ณ  ๋Š๊ปด์ง!

2011๋…„ ์ถœ๊ฐ„๋œ ์ฑ…์ด๊ณ , ์ฐธ๊ณ ํ•˜๋Š” ์ž๋ฃŒ ์ค‘ ํ•˜๋‚˜์ด๋‹ˆ๊นŒ
๊ผญ camalCase๋ฅผ ์จ์•ผํ•œ๋‹ค๋Š” ๊ฒƒ์€ ์•„๋‹ˆ๋งŒ ์ผ๋‹จ์€ ์ฑ…์—์„œ ๊ทธ๋ ‡๋‹ค!

๊ทธ๋ ‡๋‹ค๋ฉด ๊ตฌ๊ธ€์€..?

๊ตฌ๊ธ€์€ ์ฟผ๋ฆฌ์ŠคํŠธ๋ง ์–ด์ฐŒ์“ฐ๋Š”๊ฐ€?

https://www.google.com/search?rlz=1C1SQJL_enKR899KR899&biw=1920&bih=937&sxsrf=ALeKk02PAFWe8vSynzK5OZypu0G3v9nn2A%3A1604017511652&ei=Z12bX_-2J4nZhwPn95yoDw&q=query+parameters+camelcase+google&oq=query+parameters+camelcase+google&gs_lcp=CgZwc3ktYWIQAzIHCCEQChCgATIHCCEQChCgATIHCCEQChCgAToECAAQRzoFCAAQyQM6BggAEBYQHjoICCEQFhAdEB46BQghEKABUM3cIFiX5SBg_uUgaABwAngAgAGyAYgBqAeSAQMwLjaYAQCgAQGqAQdnd3Mtd2l6yAEIwAEB&sclient=psy-ab&ved=0ahUKEwi_hvvvhtvsAhWJ7GEKHec7B_U4ChDh1QMIDQ&uact=5

์œ„์˜ ์ฟผ๋ฆฌ์ŠคํŠธ๋ง์„ ์ž˜ ์‚ดํŽด๋ณด๋ฉด
"gs_lcp"๋ผ๋Š” ์ฟผ๋ฆฌ์ŠคํŠธ๋ง ํŒŒ๋ผ๋ฏธํ„ฐ ํ™•์ธ๊ฐ€๋Šฅ!
๊ตฌ๊ธ€์€ ์ฟผ๋ฆฌ์ŠคํŠธ๋ง ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ์Šค๋„ค์ดํฌ๋“œ๋กœ ์“ฐ๋Š” ๊ตฐ!

๊ตฌ๊ธ€SEO๋ฅผ ์œ„ํ•ด์„œ๋Š” URL์—๋Š” ์–ธ๋”๋ง๊ณ  ํ•˜์ดํ”ˆ

์“ฐ์„ธ์š”!

https://www.i-am-the-server.com/data?kind='weather'

๊ตฌ๊ธ€ ๊ฒ€์ƒ‰์—”์ง„์ด ์–ธ๋”๋ฐ”๋กœ ๊ตฌ๋ถ„๋œ ๊ฒฝ์šฐ๋Š” ํ•˜๋‚˜์˜ ๋‹จ์–ด๋กœ ์ธ์‹!
๋ฐ˜๋ฉด์—,
ํ•˜์ดํ”ˆ์œผ๋กœ ๊ตฌ๋ถ„๋œ ๋‹จ์–ด๋Š” ๋‹จ์–ด์ž์ฒด๋กœ ๊ตฌ๋ถ„ํ•œ๋‹ค๊ณ  ํ•œ๋‹ค!

๊ฒฐ๋ก ?!

ํŒŒ๋ผ๋ฏธํ„ฐ ๋„ค์ด๋ฐ์€ ์ผ€๋ฉ€๋กœ ์“ฐ๋Š” ๊ฒƒ์ด ๋น„๊ณต์‹์ ? ํ‘œ์ค€์ธ ๊ฒƒ ๊ฐ™์œผ๋‚˜(REST API๋ฃฐ๋ถ ์ฑ… ์˜ˆ์‹œ)
๋ฐฑ์—”๋“œ์˜ ์–ธ์–ด์— ๋”ฐ๋ผ์„œ ์ฝ”๋“œ์ž‘์„ฑ์„ ์šฉ์ดํ•˜๊ธฐ ์œ„ํ•ด์„œ ํŽธ์ด์ƒ ๋ฐฑ์—”๋“œ ์–ธ์–ด์˜ ๋„ค์ด๋ฐ ๋ฃฐ์„ ๋”ฐ๋ผ๊ฐ€๋Š” ๊ฒƒ ๊ฐ™์Œ!

์žฅ๊ณ ๋Š” snaked_case
https://i-am-the-server.com/price?product_id=111

  • ๋ฐฑ์—”๋“œ์—์„œ ์œ„์™€ ๊ฐ™์€ api๋ฅผ ํ˜ธ์ถœ๋ฐ›์œผ๋ฉด
  • get http request์—์„œ "product_id"๊ฐ€์ ธ์™€์„œ ๊ฐ’์„ ํ™•์ธํ•˜๊ณ 
  • database์—์„œ product id๊ฐ€ 111์ธ ์ œํ’ˆ์„ response http๋กœ ๋Œ๋ ค์ค€๋‹ค.
    get htttp request์—์„œ ๋ณ€์ˆ˜?๋ฅผ ๊ฐ€์ ธ์˜ฌ๋•Œ
    ๋ฐฑ์—”๋“œ์˜ ๋„ค์ด๋ฐ๋ฃฐ๊ณผ ๋งž์ถ”๋ฉด ํŽธํ•˜๊ธฐ์— ๊ทธ๋ ‡๊ฒŒ ๋ณดํ†ต์“ฐ๋Š” ๊ฒƒ ๊ฐ™๋‹ค

Reference

profile
#์˜์‹์˜ํ๋ฆ„ #์ˆœ๊ฐ„์ˆœ๊ฐ„ #์ƒ๊ฐ์˜์Šค๋ƒ…์ƒท

0๊ฐœ์˜ ๋Œ“๊ธ€