Skip to content

Library for simple REST calls with multiple retry options

License

Notifications You must be signed in to change notification settings

govindamurali/rester

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rester

Library for simple REST calls GET, POST, PUT, DELETE without worrying about nitty gritties. You could chose to make the calls with periodic retry, exponential backoff, or just once.

Install

go get github.com/govindamurali/rester

Usage

Initialize request and response structs

  type Request struct{
    SomeReqData string `json:"some_req_data"`
  }
  
  type Response struct{
    SomeRespData string `json:"some_resp_data"`
  }

Initialize request and response variables

  request:= Request{SomeReqData: "some value"}
  response:= Response{}	

Initialize request methods

  postRequest := rester.PostRequest(url, request, &response, customHeaders, customTransport)
  getRequest := rester.GetRequest(url, &response, nil, nil)    
  putRequest :=  rester.PutRequest(url, request, &response, nil, nil)   
  deleteRequest := rester.DeleteRequest(url, request, &response, customHeaders, customTransport)

Make the call

  httpResponse,err := postRequest.Once()
  httpResponse,err := getRequest.WithConstantRetry(maxTimeOutInSeconds)
  httpResponse,err := putRequest.WithExponentialRetry(maxTimeOutInSeconds)

Miscellaneous

  • You'll be able to get the response in the response variable & httpStatus in httpResponse variable
  • customHeaders are optional. Will use defaultHeaders when nil
  • customTransport is optional. Will use defaultTransport when nil. Tip - Use newrelic agent transport to get metrics tracked on newrelic.

About

Library for simple REST calls with multiple retry options

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages