http

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package http provides HTTP client functionality for making requests. Designed as a bridge for Lua functions to perform HTTP operations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	Get(req Request) (Response, error)
	Post(req Request) (Response, error)
	Put(req Request) (Response, error)
	Patch(req Request) (Response, error)
	Delete(req Request) (Response, error)
}

Client is an interface for making HTTP requests

type DefaultClient

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

DefaultClient is the default implementation of Client

func NewDefaultClient

func NewDefaultClient() *DefaultClient

NewDefaultClient creates a new default HTTP client with timeout and connection pooling

func (*DefaultClient) Delete

func (c *DefaultClient) Delete(req Request) (Response, error)

Delete performs an HTTP DELETE request

func (*DefaultClient) Get

func (c *DefaultClient) Get(req Request) (Response, error)

Get performs an HTTP GET request

func (*DefaultClient) Patch

func (c *DefaultClient) Patch(req Request) (Response, error)

Patch performs an HTTP PATCH request

func (*DefaultClient) Post

func (c *DefaultClient) Post(req Request) (Response, error)

Post performs an HTTP POST request

func (*DefaultClient) Put

func (c *DefaultClient) Put(req Request) (Response, error)

Put performs an HTTP PUT request

type Error

type Error struct {
	StatusCode int
	Message    string
	Body       string
}

Error represents an HTTP error with additional context

func (*Error) Error

func (e *Error) Error() string

type FakeClient

type FakeClient struct {
	// Responses maps method+URL to a Response
	Responses map[string]Response
	// Errors maps method+URL to an error
	Errors map[string]error
	// Requests stores all requests made (for verification)
	Requests []Request
}

FakeClient is a stub implementation of Client for testing

func NewFakeClient

func NewFakeClient() *FakeClient

NewFakeClient creates a new fake HTTP client for testing

func (*FakeClient) Delete

func (f *FakeClient) Delete(req Request) (Response, error)

Delete performs a fake HTTP DELETE request

func (*FakeClient) Get

func (f *FakeClient) Get(req Request) (Response, error)

Get performs a fake HTTP GET request

func (*FakeClient) Patch

func (f *FakeClient) Patch(req Request) (Response, error)

Patch performs a fake HTTP PATCH request

func (*FakeClient) Post

func (f *FakeClient) Post(req Request) (Response, error)

Post performs a fake HTTP POST request

func (*FakeClient) Put

func (f *FakeClient) Put(req Request) (Response, error)

Put performs a fake HTTP PUT request

func (*FakeClient) SetError

func (f *FakeClient) SetError(method, url string, err error)

SetError configures a fake error for a given method and URL

func (*FakeClient) SetResponse

func (f *FakeClient) SetResponse(method, url string, response Response)

SetResponse configures a fake response for a given method and URL

type Headers

type Headers map[string]string

Headers represents HTTP headers as a map of string key-value pairs

type Query

type Query map[string]string

Query represents URL query parameters

type Request

type Request struct {
	Method  string
	URL     string
	Headers Headers
	Query   Query
	Body    string
}

Request represents an HTTP request

type Response

type Response struct {
	StatusCode int
	Headers    Headers
	Body       string
}

Response represents an HTTP response

func (*Response) IsError

func (r *Response) IsError() bool

IsError returns true if the status code is 4xx or 5xx

func (*Response) IsSuccess

func (r *Response) IsSuccess() bool

IsSuccess returns true if the status code is 2xx

Jump to

Keyboard shortcuts

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