rest

package module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 28, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package rest provides a simple HTTP client for REST APIs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is a simple HTTP client for REST APIs.

func NewClient

func NewClient(client *http.Client, baseURI string) *Client

NewClient creates a new REST Client at the given base URI.

func (*Client) Delete

func (c *Client) Delete(path string, response any) *Error

Delete makes a DELETE request to the given path and unmarshals the response into the given response object.

  • path: the path to make the request to
  • response: a pointer to the struct to unmarshal the response into

func (*Client) Do

func (c *Client) Do(req *http.Request, response any) *Error

func (*Client) DoWithBody

func (c *Client) DoWithBody(method, path string, body any, response any) *Error

DoWithBody makes a request to the given path with the JSON encoding of the given body. It also unmarshals the JSON response into the given response object. Automatically sets the Content-Type header to application/json.

  • method: the HTTP method to use (e.g. GET, POST, PUT, DELETE)
  • path: the path to make the request to
  • body: the body to send with the request
  • response: a pointer to the struct to unmarshal the response into

func (*Client) DoWithoutBody

func (c *Client) DoWithoutBody(method, path string, response any) *Error

DoWithoutBody makes a request to the given path and unmarshals the response into the given response object.

  • method: the HTTP method to use (e.g. GET, POST, PUT, DELETE)
  • path: the path to make the request to
  • response: a pointer to the struct to unmarshal the response into

func (*Client) Get

func (c *Client) Get(path string, response any) *Error

Get makes a GET request to the given path and unmarshals the response into the given response object.

  • path: the path to make the request to
  • response: a pointer to the struct to unmarshal the response into

func (*Client) Patch

func (c *Client) Patch(path string, body any, response any) *Error

Patch makes a PATCH request to the given path with the JSON encoding of the given body. It also unmarshals the JSON response into the given response object. Automatically sets the Content-Type header to application/json.

func (*Client) Post

func (c *Client) Post(path string, body any, response any) *Error

Post makes a POST request to the given path with the JSON encoding of the given body. It also unmarshals the JSON response into the given response object. Automatically sets the Content-Type header to application/json.

func (*Client) Put

func (c *Client) Put(path string, body any, response any) *Error

Put makes a PUT request to the given path with the JSON encoding of the given body. It also unmarshals the JSON response into the given response object. Automatically sets the Content-Type header to application/json.

type Error

type Error struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

func (*Error) Error

func (e *Error) Error() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL