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

๐ŸŒฟ Spring33

6. RESTful API ์„ค๊ณ„ ๊ฐ€์ด๋“œ Richardson Maturity Model A way to grade your API according to the constraints of REST Level 0 expose soap web services in rest style https://server/getPosts Level 1 expose resources with proper url note : improper use of http methods → ๋ชจ๋“  ์š”์ฒญ์„ GET, POST๋กœ ๋ฐ›๊ฑฐ๋‚˜ ์—๋Ÿฌ/200์œผ๋กœ๋งŒ ๋ฐ˜ํ™˜ํ•˜๋Š” ํ˜•ํƒœ https://server/accounts/10 Level 2 level1 + HTTP methods(GET, POST, PUT, DELETE ๊ตฌ๋ถ„) Level 3 level2 + HATEOAS DATA + NEXT .. 2023. 6. 20.
5. Java Persistence API ์‚ฌ์šฉ JPA ๊ฐœ์š” JPA Java Persistence API ์ž๋ฐ” ORM ๊ธฐ์ˆ ์— ๋Œ€ํ•œ API ํ‘œ์ค€ ๋ช…์„ธ(Object Relationship Mapping) ์ž๋ฐ” ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์—์„œ ๊ด€๊ณ„ํ˜• ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ์‹์„ ์ •์˜ํ•œ ์ธํ„ฐํŽ˜์ด์Šค → ๋ฉ”์†Œ๋“œ ์„ ์–ธ๋ฌธ๋งŒ ์กด์žฌ. ์šฐ๋ฆฌ๋Š” ๊ตฌํ˜„์ฒด๋ฅผ ๊ฐ€์ง€๊ณ  ๊ฐœ๋ฐœ์„ ํ•ด์•ผ ํ•œ๋‹ค ⇒ Hibernate EntityManager๋ฅผ ํ†ตํ•ด CRUD ์ฒ˜๋ฆฌ Hibernate JPA์˜ ๊ตฌํ˜„์ฒด, ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ์ง์ ‘ ๊ตฌํ˜„ํ•œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ⇒ JPA์˜ EntityManager๋ฅผ ๊ตฌํ˜„ ๊ฐ์ฒด ๊ด€๊ณ„ ๋งคํ•‘ ํ”„๋ ˆ์ž„์›Œํฌ ์ƒ์‚ฐ์„ฑ, ์œ ์ง€๋ณด์ˆ˜, ๋น„์ข…์†์„ฑ Spring Data JPA Spring Module JPA๋ฅผ ์ถ”์ƒํ™”ํ•œ Repository ์ธํ„ฐํŽ˜์ด์Šค ์ œ๊ณต ์ธํ„ฐํŽ˜์ด์Šค ์„ ์–ธ ๋งŒ์œผ๋กœ๋„ Spring์—์„œ ์ œ๊ณตํ•˜๋Š” CRUD ๊ธฐ๋Šฅ ์‚ฌ์šฉ.. 2023. 6. 20.
4. Spring Boot API ์‚ฌ์šฉ REST API Level 3๋ฅผ ์œ„ํ•œ HATEOAS ์„ค์ • HATEOAS Hypermedia As the Engine Of Application State ํ˜„์žฌ ๋ฆฌ์†Œ์Šค์™€ ์—ฐ๊ด€๋œ(ํ˜ธ์ถœ ๊ฐ€๋Šฅํ•œ) ์ž์› ์ƒํƒœ ์ •๋ณด๋ฅผ ์ œ๊ณต REST API ์„ค๊ณ„ ๋‹จ๊ณ„ The Swamp of POX : ํŠน์ •ํ•œ ์›น ํ”„๋กœํ† ์ฝœ์„ ํ†ตํ•ด์„œ ์ปดํ“จํ„ฐ๊ฐ€ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ์ž์›์„ ์˜๋ฏธ ์—†์ด ์ „๋‹ฌ Resources HTTP Verbs : http ์ƒํƒœ ๋ฉ”์†Œ๋“œ๋ฅผ ์ด์šฉ Hypermedia controls : ๋ฆฌ์†Œ์Šค์˜ ์ •๋ณด๋ฅผ ์ถ”๊ฐ€์ ์œผ๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ๋ฆฌ์†Œ์Šค์™€ ํ•จ๊ป˜ ์ „๋‹ฌ org.springframework.boot spring-boot-starter-hateoas IntelliJ์—์„œ ๊ฒ€์ƒ‰ shift key 2๋ฒˆ ๋ˆ„๋ฅด๊ธฐ → pom.xml ์„ ํƒ ๋ฒ„์ „๋ณ„ HATEOAS.. 2023. 6. 20.
3. RESTful Service ๊ธฐ๋Šฅ ํ™•์žฅ Validation API @Valid annotation ์‚ฌ์šฉ **pom.xml์— dependency ์ถ”๊ฐ€** org.hibernate.validator hibernate-validator 6.0.7.Final dto์— ์ œ์•ฝ์กฐ๊ฑด ์ถ”๊ฐ€ @Data @AllArgsConstructor public class User { private Integer id; @Size(min=2, message = "Name์€ 2๊ธ€์ž ์ด์ƒ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”.") private String name; private String password; @Past // ๊ณผ๊ฑฐ ๋‚ ์งœ๋งŒ ๊ฐ€๋Šฅํ•œ ์ œ์•ฝ ์กฐ๊ฑด private Date joinDate; } controller์— ์ถ”๊ฐ€ JDK์— ํฌํ•จ๋œ API์™€ hibernate library์— ํฌํ•จ๋œ vali.. 2023. 6. 20.