{"id":37177594,"url":"https://github.com/bettercode-oss/rest","last_synced_at":"2026-01-14T20:42:48.329Z","repository":{"id":57569433,"uuid":"344608386","full_name":"bettercode-oss/rest","owner":"bettercode-oss","description":"REST API 호출 클라이언트 Golang 모듈","archived":false,"fork":false,"pushed_at":"2023-01-21T09:35:56.000Z","size":32,"stargazers_count":12,"open_issues_count":0,"forks_count":4,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-06-19T23:11:49.583Z","etag":null,"topics":["go","golang","json","rest","rest-client"],"latest_commit_sha":null,"homepage":"","language":"Go","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/bettercode-oss.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}},"created_at":"2021-03-04T21:01:25.000Z","updated_at":"2024-05-07T02:55:41.000Z","dependencies_parsed_at":"2023-01-31T10:55:14.416Z","dependency_job_id":null,"html_url":"https://github.com/bettercode-oss/rest","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/bettercode-oss/rest","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bettercode-oss%2Frest","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bettercode-oss%2Frest/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bettercode-oss%2Frest/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bettercode-oss%2Frest/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bettercode-oss","download_url":"https://codeload.github.com/bettercode-oss/rest/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bettercode-oss%2Frest/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28434494,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T18:57:19.464Z","status":"ssl_error","status_checked_at":"2026-01-14T18:52:48.501Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["go","golang","json","rest","rest-client"],"created_at":"2026-01-14T20:42:47.695Z","updated_at":"2026-01-14T20:42:48.316Z","avatar_url":"https://github.com/bettercode-oss.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Golang Rest Client\n\nGolang에서 기본적으로 제공하는 [http 패키지](https://golang.org/pkg/net/http/) 는 JSON을 기반으로 하는 REST API를 호출할 때 \nHTTP Request/Response Body를 JSON으로 변환(json.Marshal/Unmarshal)해야 하는 불편함이 있다.\n\n아래는 GET/POST 방식 호출 예시이다.\n```golang\n// HTTP POST 예시\nrequestBody := map[string]interface{}\nrequestBody[\"name\"] = \"Yoo Young-mo\"\nrequestBody[\"email\"] = \"gigamadness@gmail.com\"\n\npbytes, _ := json.Marshal(requestBody)\nbuff := bytes.NewBuffer(pbytes)\nresp, err := http.Post(\"http://example.com\", \"application/json\", buff)\n// ...\n```\nGET 방식으로 호출할 때 `http.Get` 함수는 HTTP Header를 지원하지 않기 때문에 아래와 같이 http.Client를 따로 만들어서 사용해야 한다.\n```golang\n// HTTP GET 예시\nreq, err := http.NewRequest(http.MethodGet, \"http://example.com\", nil)\nreq.Header.Set(\"Content-Type\", \"application/json;charset=UTF-8\")\n\nclient := \u0026http.Client{}\nresp, err := client.Do(req)\ndefer resp.Body.Close()\n\nbytes, _ := ioutil.ReadAll(resp.Body)\n// ...\nvar responseBody = map[string]interface{}{}\njson.Unmarshal(bytes, \u0026responseBody)\n```\n\n## 제공하는 기능\n* REST 호출 시 자동 JSON 변환(마샬링/언마샬링) 제공\n* HTTP Request \u0026 Response 로그 지원\n* HTTP Request Timeout 지원\n* HTTP Request Retry 지원\n\n## 사용법\n### 설치\n```shell\ngo get github.com/bettercode-oss/rest\n```\n\n### REST API 호출 예시\n\nRest Client는 기본적으로 HTTP Request 헤더에 `Content-Type`을 `application/json;charset=UTF-8`로 설정한다.\n\n#### GET\n\n```go\nimport (\n  \"github.com/bettercode-oss/rest\"\n)\n// ...\nclient := rest.Client{}\nresponseObject := struct {\n  Id   string `json:\"id\"`\n  Name string `json:\"name\"`\n  Age  int    `json:\"age\"`\n}{}\n\nerr := client.\n\tRequest().\n\tSetResult(\u0026responseObject).\n\tGet(\"http://example.com\")\n```\n\n#### POST\n\n```go\nimport (\n  \"github.com/bettercode-oss/rest\"\n)\n// ...\nclient := rest.Client{}\nrequestObject := struct {\n  Id   string `json:\"id\"`\n  Name string `json:\"name\"`\n  Age  int    `json:\"age\"`\n}{\n  Id:   \"gigamadness@gmail.com\",\n  Name: \"Yoo Young-mo\",\n  Age:  20,\n}\n\nerr := client.\n\tRequest().\n\tSetBody(requestObject).\n\tPost(\"http://example.com\")\n```\n\n#### PUT\n\n```go\nimport (\n  \"github.com/bettercode-oss/rest\"\n)\n// ...\nclient := rest.Client{}\nrequestObject := struct {\n  Id   string `json:\"id\"`\n  Name string `json:\"name\"`\n  Age  int    `json:\"age\"`\n}{\n  Id:   \"gigamadness@gmail.com\",\n  Name: \"Yoo Young-mo\",\n  Age:  20,\n}\n\nerr := client.\n\tRequest().\n\tSetBody(requestObject).\n\tPut(\"http://example.com\")\n```\n\n#### DELETE\n\n```go\nimport (\n  \"github.com/bettercode-oss/rest\"\n)\n// ...\nclient := rest.Client{}\nrequestObject := struct {\n  Id   string `json:\"id\"`\n  Name string `json:\"name\"`\n  Age  int    `json:\"age\"`\n}{\n  Id:   \"gigamadness@gmail.com\",\n  Name: \"Yoo Young-mo\",\n  Age:  20,\n}\n\nerr := client.\n\tRequest().\n\tSetBody(requestObject).\n\tDelete(\"http://example.com\")\n```\n\n#### HTTP 헤더 추가 하기\n\nRest Client는 기본적으로 헤더에 `Content-Type`에 `application/json;charset=UTF-8`을 추가한다.\n이외에 헤더를 추가하고 싶다면 아래 처럼 추가한다.\n```go\nclient := rest.Client{}\nresponseObject := struct {\n  Id   string `json:\"id\"`\n  Name string `json:\"name\"`\n  Age  int    `json:\"age\"`\n}{}\n\nerr := client.\n\tRequest().\n        SetHeader(\"Accept\", \"application/json\").\n\tSetHeader(\"Authorization\", \"a9ace025c90c0da2161075da6ddd3492a2fca776\").\n\tSetResult(\u0026responseObject).\n\tGet(\"http://example.com\")\n```\n\n### HTTP Request/Response 로깅(Logging)\nRest Client 생성할 때 `ShowHttpLog`를 `true`로 설정한다.\n```go\nclient := rest.Client{ShowHttpLog: true}\n```\n아래와 같이 로그를 확인할 수 있다.\n```\nbettercode-oss/rest - 2021/03/11 07:06:36 Request method=GET url=http://localhost:51716 header=map[Authorization:[a9ace025c90c0da2161075da6ddd3492a2fca776] Content-Type:[application/json;charset=UTF-8]] body=\nbettercode-oss/rest - 2021/03/11 07:06:36 Response method=GET url=http://localhost:51716 status=200 durationMs=4 header=map[Content-Length:[89] Content-Type:[text/plain; charset=utf-8] Date:[Wed, 10 Mar 2021 22:06:36 GMT]] \nbody={\n    \"id\": \"gigamadness@gmail.com\",\n    \"name\": \"Yoo Young-mo\",\n    \"age\": 20\n}\n```\n\n### HTTP Request Timeout 설정\nRest Client 생성할 때 `Timeout`을 지정한다.\n```go\nclient := rest.Client{\n  Timeout:     10 * time.Second\n}\n```\n\n### HTTP Request Retry\nRest Client 생성할 때 재시도 최대 횟수(`RetryMax`)를 지정한다.\n추가로 재시도 지연시간(`RetryDelay`)을 지정할 수 있다.\n```go\nclient := rest.Client{\n  RetryMax:    5,\n  RetryDelay:  1 * time.Second,\n}\n```\n위와 같이 설정하면 HTTP 응답 코드가 500번대(Server Error)인 경우 다시 HTTP 요청한다.\n최대 5번 하게 되며 시도 사이의 지연 시간은 1초이다.\n\n### Error 처리\nHTTP Status 에 따라 에러 처리가 필요한 경우 아래와 같이 확인할 수 있다.\n주의. HttpServerError 만 반환하는 것은 아니다. HTTP Request 과정에서 발생한 error 만  HttpServerError를 반환한다.\n```go\nerr := client.\n\t\tRequest().\n\t\tSetResult(\u0026responseObject).\n\t\tGet(\"http://example.com/err-url\")\n\nif httpErr, ok := err.(*HttpServerError); ok {\n\t// ...  \t\t\n}\n```\n\n### SSL 인증서 오류(x509) 무시 옵션\n`InsecureSkipVerify` 를 true로 설정한다.\n```go\nclient := rest.Client{\n  // ...\n  InsecureSkipVerify: true,\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbettercode-oss%2Frest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbettercode-oss%2Frest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbettercode-oss%2Frest/lists"}