Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/henomis/restclientgo
REST client for Go
https://github.com/henomis/restclientgo
api client go model rest
Last synced: 9 days ago
JSON representation
REST client for Go
- Host: GitHub
- URL: https://github.com/henomis/restclientgo
- Owner: henomis
- License: mit
- Created: 2023-03-16T07:59:44.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-01-27T23:49:33.000Z (10 months ago)
- Last Synced: 2024-01-28T00:52:08.336Z (10 months ago)
- Topics: api, client, go, model, rest
- Language: Go
- Homepage:
- Size: 31.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# RESTclientGo
[![Build Status](https://github.com/henomis/restclientgo/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/henomis/restclientgo/actions/workflows/test.yml?query=branch%3Amain) [![GoDoc](https://godoc.org/github.com/henomis/restclientgo?status.svg)](https://godoc.org/github.com/henomis/restclientgo) [![Go Report Card](https://goreportcard.com/badge/github.com/henomis/restclientgo)](https://goreportcard.com/report/github.com/henomis/restclientgo) [![GitHub release](https://img.shields.io/github/release/henomis/restclientgo.svg)](https://github.com/henomis/restclientgo/releases)
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.```go
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.```go
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](examples/cmd/) folder for usage examples.