gorestclient

package module
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2024 License: MIT Imports: 5 Imported by: 0

README

gorestclient

Go Reference

A Go client library for interacting with RESTful APIs.

Features

  • Easy to use
  • Supports JSON

Installation

go get -u github.com/aafak/gorestclient

Usage:

package main

import (
	"fmt"
	"net/http"

	"github.com/aafak/gorestclient"
)

func main() {
	restClient := gorestclient.NewRestClient()
	req, err := restClient.BuildRequest(http.MethodGet, "https://jsonplaceholder.typicode.com/posts")
	if err != nil {
		fmt.Printf("Failed to build request, Err : %v\n", err)
	}
	resp, err := restClient.ExecuteRequest(req)
	if err != nil {
		fmt.Printf("Failed to send request, Err : %v, resp: %v, \n", err, resp)
	}
	defer resp.Body.Close()
	fmt.Println(resp)


POST request:
	req, _ := restClient.BuildRequest("POST", "https://jsonplaceholder.typicode.com/posts", `{"title": "foo","body": "bar","userId": 1}`)
	resp, err := restClient.ExecuteRequest(req)
	fmt.Println(resp)

Restclient with SSL certificates

	restClient, _ := NewRestClientWithCerts("cert.pem", "privkey.pem")

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RestClient

type RestClient struct {
	Client *http.Client
}

func (*RestClient) BuildRequest

func (r *RestClient) BuildRequest(method, url string, body ...string) (*http.Request, error)

func (*RestClient) ExecuteRequest

func (rc *RestClient) ExecuteRequest(req *http.Request) (*http.Response, error)

type RestClientInterface

type RestClientInterface interface {
	ExecuteRequest(req *http.Request) (*http.Response, error)
	BuildRequest(method, url string, body ...string) (*http.Request, error)
}

func NewRestClient

func NewRestClient() RestClientInterface

func NewRestClientWithCerts added in v1.0.5

func NewRestClientWithCerts(certFilePath, privateKeyFilePath string) (RestClientInterface, error)

Jump to

Keyboard shortcuts

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