CRUD Restful Web Service: RestTemplate을 이용 :: 행복한 프로그래머

posted by 쁘로그램어 2018. 5. 3. 22:27

스프링부트의 Restful 예제이다.

RestServer 및 Client 모두 따라해봤는데 정상적으로 동작한다.


# CRUD Restful Web Service with Spring Boot Example

참고: https://o7planning.org/en/11645/crud-restful-web-service-with-spring-boot-example


Restful Web Service 간단한 예제이다.

SpringBootCrudRestfulApplication.java을 실행하면 된다.

전체적인 프로젝트 구조는 아래와 같다.



SprintBootCrudRestful.zip


아래와 같이 접속하면 동작하지만,

http://localhost:8080/employees


아래와 같이 접속하면 에러가 난다.

http://localhost:8080/employees.json

http://localhost:8080/employees.xml


구글링을 해보니까 REST로 Response를 줄때 JSON, XML 형태 모두 지원하려면 아래와 같이 해야한다.

참고: http://www.javainuse.com/spring/sprrest

참고: http://www.javainuse.com/spring/rest4



# Spring Boot Restful Client with RestTemplate example

참고: https://o7planning.org/en/11647/spring-boot-restful-client-with-resttemplate-example


REST Client로 GET, POST, PUT, DELETE하는 예제이다.

전체적인 프로젝트 구조는 아래와 같다.


SprintBootRestCient.zip

GetWithHeaderExample.java에는 Influx DB에 REST로 데이터를 조회하는 것으로 조금 수정했다. 

 // Request to return JSON format

headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);   <--- URL ENCODED


'Java > Springboot' 카테고리의 다른 글

SpringBoot with Docker : Docker 이미지 생성  (0) 2018.05.23
스프링부트 학습 정리 자료  (0) 2018.05.17