๐Ÿ’ Spring/Spring REST API

๐Ÿ’ Spring/Spring REST API

2) [test] JSON ์‘๋‹ต์œผ๋กœ 201์ด ๋‚˜์˜ค๋Š”์ง€ ํ™•์ธ - ์Šคํ”„๋ง REST API

Test 1) JSON ์‘๋‹ต์œผ๋กœ 201์ด ๋‚˜์˜ค๋Š”์ง€ ํ™•์ธ. - Location ํ—ค๋”์— ์ƒ์„ฑ๋œ ์ด๋ฒคํŠธ๋ฅผ ์กฐํšŒํ•  ์ˆ˜ ์žˆ๋Š” URI ๋‹ด๊ฒจ ์žˆ๋Š”์ง€ ํ™•์ธ. - id๋Š” DB์— ๋“ค์–ด๊ฐˆ ๋•Œ ์ž๋™ ์ƒ์„ฑ๋œ ๊ฐ’์œผ๋กœ ๋‚˜์˜ค๋Š”์ง€ ํ™•์ธ. ์ผ๋‹จ Test ํด๋ž˜์Šค๋ฅผ ๋งŒ๋“ ๋‹ค ํ…Œ์ŠคํŠธ๋ฅผ ํ•  ํด๋ž˜์Šค์—์„œ ๋งฅ ๊ธฐ์ค€์œผ๋กœ ๋‹จ์ถ•ํ‚ค cmd + shift + T ๋ฅผ ๋ˆŒ๋Ÿฌ์ฃผ๋ฉด ํ…Œ์ŠคํŠธ ํด๋ž˜์Šค ์ƒ์„ฑํ•ด์ค€๋‹ค. Location URI๋ฅผ ๋งŒ๋“ค๊ฑด๋ฐ, ์—ฌ๊ธฐ์„œ๋Š” HATEOAS๊ฐ€ ์ œ๊ณตํ•˜๋Š” linkTo() , methodOn()์„ ์‚ฌ์šฉํ•  ๊ฒƒ ์ด๋‹ค. ๊ฐ์ฒด๋ฅผ JSON์œผ๋กœ ๋ณ€ํ™˜ ํ• ๋•Œ, ObjectMapper๋ฅผ ์‚ฌ์šฉ. EventController ๊ตฌํ˜„ package me.iseunghan.demoinflearnrestapi.events; import org.springframework...

๐Ÿ’ Spring/Spring REST API

1) Spring-Boot ํ”„๋กœ์ ํŠธ ๋งŒ๋“ค๊ธฐ - ์Šคํ”„๋ง REST API

์˜์กด์„ฑ ์ถ”๊ฐ€ WEB JPA Hateoas H2 Lombok Event ์ƒ์„ฑ API ๊ตฌํ˜„ : ๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง Event ์ƒ์„ฑ API package me.iseunghan.demoinflearnrestapi.events; import lombok.*; import javax.persistence.*; import java.time.LocalDateTime; //hashcode์—์„œ of="id"๋กœ ์ค€ ์ด์œ ? ์—ฐ๊ด€๊ด€๊ณ„๊ฐ€ ์žˆ์„๋•Œ ๊ทธ ๊ด€๊ณ„๊ฐ€ ์ƒํ˜ธ์ฐธ์กฐ ๊ด€๊ณ„์—์„œ ์ฐธ์กฐํ•˜๋Š” ์ƒํ™ฉ์—์„œ ์Šคํƒ์˜ค๋ฒ„ํ”Œ๋กœ์šฐ๊ฐ€ ๋ฐœ์ƒํ• ์ˆ˜๊ฐ€ ์žˆ๊ธฐ๋•Œ๋ฌธ์—, id๋กœ๋งŒ ํ•ด์‹œ์ฝ”๋“œ๋ฅผ ์ƒ์„ฑํ•œ๋‹ค. //์„œ๋กœ๊ฐ„์— ๋ฉ”์†Œ๋“œ๋ฅผ ๊ณ„์† ๊ณ„์† ํ˜ธ์ถœํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์Šคํƒ์˜ค๋ฒ„ํ”Œ๋กœ์šฐ๊ฐ€ ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ๋‹ค. @Builder @AllArgsConstructor @NoArgsConstructor @Ge..

iseunghan
'๐Ÿ’ Spring/Spring REST API' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๊ธ€ ๋ชฉ๋ก (2 Page)