Skip to content

henomis/restclientgo

Repository files navigation

RESTclientGo

Build Status GoDoc Go Report Card GitHub release

REST client for Go focusing on Request and Response data modeling.

Rest methods

restclientgo offers the following methods

  • GET
  • POST
  • PUT
  • DELETE
  • PATCH

Modeling

Request

Define your request model and attach restclientgo methods to satisfy the Request interface.

type MyRequest struct {
    // Add your request fields here
    // ID string `json:"id"`
    // ...
}

func (r *MyRequest) Path() (string, error) {
    // Return the path of the request including the query string if any.
}

func (r *MyRequest) Encode() (io.Reader, error) {
    // Return the request body as string
}

func (r *MyRequest) ContentType() string {
    // Return the content type of the request
}

Response

Define your response model and attach restclientgo methods to satisfy the Response interface.

type MyResponse struct {
    // Add your response fields here
    // ID string `json:"id"`
    // ...
}

func (r *MyResponse) Decode(body io.Reader) error {
    // Decode the response body into the response model
}

func (r *MyResponse) SetBody(body io.Reader) error {
    // Set the response body if needed
}

func (r *MyResponse) SetStatusCode(code int) error {
    // Handler to set the HTTP status code of the response
}

func (r *MyResponse) AcceptContentType() string {
    // Return the accepted content type of the response
}

// Optional. Implement this method if you want to stream the response body.
func (r *MyResponse) StreamCallback() StreamCallback {
    // Return the stream callback if any.
}

Usage

Please referr to the examples folder for usage examples.