goxios

package module
v0.0.0-...-b44f477 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2024 License: MIT Imports: 9 Imported by: 2

README

Goxios

GoReport

Goxios is an HTTP client written in Go, inspired by Axios

Introduction:

Goxios is a powerful HTTP client library for Go developers, heavily inspired by the renowned Axios library in JavaScript. It aims to simplify the process of making HTTP requests in Go, offering a clean and intuitive API while focusing on performance and memory efficiency.

Key Features:

  • Axios-inspired API: Goxios provides an API that will feel familiar to developers who have experience with Axios, making it easy to transition between JavaScript and Go projects.

  • Fast Development: By abstracting away low-level details and providing a high-level interface, Goxios accelerates development, allowing you to focus on building your application logic without getting bogged down by HTTP client intricacies.

Getting Started:

To start using Goxios in your project, simply import it and begin making requests:

package main

import (
	"context"
	"fmt"
	"io"

	"github.com/Simplou/goxios"
)

func main() {
    // Create a new Goxios client
    client := goxios.New(context.Background())

    // Make a GET request
    requestOpts := &goxios.RequestOpts{Headers: []goxios.Header{}}
    resp, err := client.Get("https://api.sampleapis.com/codingresources/codingResources", requestOpts)
    if err != nil {
       panic(err)
    }
    defer resp.Body.Close()
    // Save the response body bytes in 'b'
    b, err := io.ReadAll(resp.Body)
    if err != nil {
        panic(err)
    }
    fmt.Println(string(b)) // Print the content of 'b' as a string
}

For more advanced usage and customization options, refer to the documentation on GoDoc. .

License:

Goxios is licensed under the MIT License. See the LICENSE file for details.

Acknowledgements:

Special thanks to the developers of Axios for their inspiration.

Maintainer:

Gabriel Luiz - @gabrielluizdev


Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeJSON

func DecodeJSON(body io.Reader, v any) error

DecodeJSON decodes JSON data from the provided io.Reader into the given value.

func New

func New(ctx context.Context) *clientV2

New creates and returns a new HTTP client with the provided context. It initializes and returns a new clientV2 pointer with an embedded http.Client pointer, an empty request pointer, and the provided context.

func NewClient

func NewClient(ctx context.Context) *client

NewClient creates a new HTTP client with the given context. It initializes and returns a new client pointer with an embedded http.Client pointer, an empty request pointer, and the provided context.

func UnmarshalJSON

func UnmarshalJSON(data []byte, v any) error

UnmarshalJSON parses the JSON-encoded data and stores the result in the value pointed to by v.

Types

type GenericJSON

type GenericJSON[T any] map[string]T

GenericJSON represents a generic JSON object with keys of type string and values of any type. It allows flexibility in defining JSON objects with various value types.

func (GenericJSON[T]) Marshal

func (gj GenericJSON[T]) Marshal() ([]byte, error)

Marshal converts the GenericJSON object to its JSON representation.

func (GenericJSON[T]) Unmarshal

func (gj GenericJSON[T]) Unmarshal(v any) error
type Header struct {
	Key   string
	Value any
}

Header represents an HTTP header key-value pair.

type JSON

type JSON map[string]interface{}

JSON represents a JSON object.

func (JSON) Marshal

func (j JSON) Marshal() ([]byte, error)

Marshal converts the JSON object to its JSON representation.

func (JSON) Unmarshal

func (j JSON) Unmarshal(v any) error

type QueryParam

type QueryParam struct {
	Key   string // The key of the query parameter.
	Value any    // The value of the query parameter.
}

QueryParam represents a single key-value pair for query parameters.

type RequestOpts

type RequestOpts struct {
	Headers     []Header
	Body        io.Reader
	QueryParams []QueryParam
}

Jump to

Keyboard shortcuts

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