๐ฟ Spring/โ RESTful Web Service7 2. User Service API ๊ตฌํ User ๋๋ฉ์ธ ํด๋์ค ์์ฑ ๋๋ฉ์ธ ํน์ ์ ๋ฌธ ๋ถ์ผ์์ ์ฌ์ฉ๋๋ ์ ๋ฌธ ์ง์ ์คํ ๋ ์คํ์ ํด๋น ํด๋์ค๊ฐ ์ด๋ ์ฉ๋๋ก ์ฌ์ฉ๋ ๊ฒ์ธ์ง ๋ํ๋ด๋ ๊ฒ → ์์กด์ฑ ์ฃผ์ ์ ๋์๋๋ค. ex) @RestController, @Service POST @RequestBody ๋ฅผ ์ ์ธํด ํ์ฌ variable์ด requestbody ํ์์ผ๋ก ๋ค์ด์จ๋ค๋ ๊ฒ์ ์๋ฆผ HTTP Status Code 2XX → OK 4XX → Client 5XX → Server @ServletUriComponentsBuilder๋ฅผ ์ด์ฉํด ํธ์ถ ๋ฐฉ๋ฒ์ ๋ฐ๋ผ ์ ์ ํ status code๋ฅผ ๋ฐํํจ @PostMapping("/users") public ResponseEntity createUser(@RequestBody User user){ User save.. 2023. 6. 20. 1. Spring Boot๋ก ๊ฐ๋ฐํ๋ RESTful Service ํ๋ก์ ํธ ์์ฑ dependency ⇒ pom.xml JPA Spring web → embedded tomcat ์คํ ๊ฐ๋ฅ REST API ์ค๊ณ User → Posts ๊ตฌ์กฐ ํ์ธ application.properties → yml ํ์ผ๋ก! ์คํ๋ง ๋ถํธ ํ๊ฒฝ์ค์ ์ง์ pom.xml ์ ์ฒด ํ๋ก์ ํธ์ ํ์ํ maven ์ค์ Controller RESTController ํด๋์ค๋ก ์๋ํจ(์ผ๋ฐ MVC Controller์๋ ๋ค๋ฆ) @RestController Mapping // GET @RequestMapping(method=RequestMethod.GET, path="/hello-world") @GetMapping(path = "/hello-world")/ Bean ์คํ๋ง์์ ์ ์ธ๋์ด ๊ด๋ฆฌ๋๋ ์ธ์คํด์ค ⇒ ์์กด์ฑ.. 2023. 6. 20. 0. Web Service & Web Application ์น ์๋น์ค ๋คํธ์ํฌ ์์์ ์๋ก ๋ค๋ฅธ ์ข ๋ฅ์ ์ปดํจํฐ๋ค ๊ฐ์ ์ํธ์์ฉํ๊ธฐ ์ํ ์ํํธ์จ์ด ์์คํ SOAP VS REST 1) SOAP(Simple object access protocol) XML ๊ธฐ๋ฐ envelope - header - body ⇒ overhead ์ฌํจ 2) REST(REpresentational State Transfer) Resource์ representation์ ์ํ (์์์) ์ํ ์ ๋ฌ HTTP Method๋ฅผ ํตํด Resource๋ฅผ ์ฒ๋ฆฌํ๊ธฐ ์ํ ์ํคํ ์ณ RESTful : REST API๋ฅผ ์ ๊ณตํ๋ ์น ์๋น์ค REST HTTP HTTP Methods : ํด๋ผ์ด์ธํธ๊ฐ ์๋ฒ์๊ฒ ์ ๋ฌํ๊ฒ ๋๋ ๋ชฉ์ ์ด๋ ์ข ๋ฅ๋ฅผ ์๋ ค์ฃผ๋ ์๋จ HTTP Status Codes : ํด๋ผ์ด์ธํธ๊ฐ ์์ฒญํ ์ ๋ณด.. 2023. 6. 20. ์ด์ 1 2 ๋ค์