{"id":25497593,"url":"https://github.com/mango606/spring-proficient-week2","last_synced_at":"2026-01-23T09:04:21.210Z","repository":{"id":276724628,"uuid":"930087408","full_name":"mango606/spring-proficient-week2","owner":"mango606","description":"Spring Master 4주차","archived":false,"fork":false,"pushed_at":"2025-02-10T04:06:00.000Z","size":0,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-10T04:27:28.871Z","etag":null,"topics":["monorepo","resttemplate"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mango606.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-02-10T03:34:41.000Z","updated_at":"2025-02-10T04:06:03.000Z","dependencies_parsed_at":"2025-02-10T04:37:42.216Z","dependency_job_id":null,"html_url":"https://github.com/mango606/spring-proficient-week2","commit_stats":null,"previous_names":["mango606/spring-proficient-week2"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mango606%2Fspring-proficient-week2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mango606%2Fspring-proficient-week2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mango606%2Fspring-proficient-week2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mango606%2Fspring-proficient-week2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mango606","download_url":"https://codeload.github.com/mango606/spring-proficient-week2/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239579819,"owners_count":19662674,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["monorepo","resttemplate"],"created_at":"2025-02-19T01:28:04.065Z","updated_at":"2025-11-10T09:30:22.082Z","avatar_url":"https://github.com/mango606.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# RestTemplate\n\n## 1. RestTemplate 소개\n\n`RestTemplate`은 Spring에서 제공하는 HTTP 클라이언트 툴로, 서버에서 다른 서버로 요청을 보낼 수 있도록 도와줍니다. 클라이언트(브라우저)로부터 요청을 받는 것이 아니라, 서버가 다른 서버에게 요청을 보내는 서버 투 서버(Server To Server) 통신을 간편하게 구현할 수 있습니다.\n\n### 서버 투 서버 통신의 필요성\n\n개발을 진행하면서 라이브러리만으로 구현이 어려운 기능들이 많이 있습니다. 예를 들어, 회원가입 시 사용자의 주소 정보를 받아야 할 때, 주소를 검색하는 기능을 직접 구현하면 많은 시간과 비용이 소모됩니다. 이런 경우, 카카오에서 제공하는 [주소 검색 API](https://postcode.map.daum.net/guide)와 같은 외부 API를 활용할 수 있습니다.\n\n서버가 클라이언트의 역할을 하여 다른 서버에게 요청을 보내는 경우, `RestTemplate`을 사용하여 간편하게 구현할 수 있습니다.\n\n## 2. RestTemplate 사용 방법\n\n다음과 같이 프로젝트 2개를 만들어서 두 개의 서버를 동시에 실행하여 서로 통신할 수 있게 설정합니다.\n\n1. **클라이언트 서버**: 8080 포트에서 실행\n2. **대상 서버**: 7070 포트에서 실행\n\n### Get 요청 방법\n\n- **클라이언트 입장의 서버:** 요청을 보낼 때, `RestTemplate`을 주입받아 사용합니다. `UriComponentsBuilder`를 이용하여 요청 URI를 구성하고, `getForEntity()` 메서드로 요청을 보내어 응답을 받습니다.\n- **서버 입장의 서버:** 요청에 따라 데이터를 조회하고 응답합니다.\n\n### Post 요청 방법\n\n- **데이터 전송:** `postForEntity()` 메서드를 사용하여 데이터를 POST 방식으로 전송합니다. 요청 URI는 `UriComponentsBuilder`로 동적으로 생성하며, 요청과 함께 객체를 전송합니다.\n- **응답 처리:** 서버는 전송된 데이터를 받아 처리하고, 필요한 객체를 응답합니다.\n\n### Exchange 메서드 사용\n\n- **복잡한 요청 처리:** `exchange()` 메서드를 사용하면, 요청 헤더에 정보를 추가하거나 다양한 HTTP 메서드를 사용하여 보다 복잡한 요청을 처리할 수 있습니다.\n- **응답 처리:** 전달받은 요청에 대해 서버는 헤더와 바디 정보를 확인하고 적절한 응답을 제공합니다.\n\n## 사용 예시\n\n- **단일 아이템 조회:** 클라이언트는 특정 조건에 맞는 아이템을 조회하여 받아옵니다.\n- **리스트 조회:** 클라이언트는 아이템 리스트를 조회하며, 서버는 조건에 맞는 아이템들을 JSON 형태로 반환합니다. 클라이언트는 이 JSON을 객체 리스트로 변환하여 사용합니다.\n\n## 기술 스택\n\n- Spring Boot\n- RestTemplate\n- JSON\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmango606%2Fspring-proficient-week2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmango606%2Fspring-proficient-week2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmango606%2Fspring-proficient-week2/lists"}