api

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2022 License: MIT Imports: 12 Imported by: 1

README

fasthttp-api

fasthttp-api use fasthttp to sending request. In short, fasthttp server is up to 10 times faster than net/http. Below are benchmark results. Benchmark

This repo still under development. We accept any pull request. ^_^

Installation

  // dependency
  $ go get github.com/myussufz/fasthttp-api
  $ go get github.com/valyala/fasthttp

Quick Start

Simple Request Method
JSON Usage
    var request struct {
        Name string `json:"name"`
    }

    request.Name = "test"

    var response struct {
        Name string `json:"name"`
    }

    if err = api.Fetch("http://google.com", &api.Option{
            Method: http.MethodPost,
            ContentType: api.ContentTypeJSON,
            Body: request,
        }).ToJSON(&response); err != nil {
        log.Println("error: ", err)
    }
XML Usage
  var request struct {
        Name string `xml:"name"`
    }

    request.Name = "test"

    var response struct {
        Name string `xml:"name"`
    }

    if err = api.Fetch("http://google.com", &api.Option{
            Method: http.MethodPost,
            ContentType: api.ContentTypeXML,
            Body: request,
        }).ToXML(&response); err != nil {
        log.Println("error: ", err)
    }
Return String
  var request struct {
        Name string `json:"name"`
    }

    request.Name = "test"

    data, err = api.Fetch("http://google.com", &api.Option{
        Method: http.MethodPost,
        ContentType: api.ContentTypeJSON,
        Body: request,
    }).ToString();
    if err != nil {
        log.Println("error: ", err)
    }

    log.Println("data: ", data)

Documentation

Index

Constants

View Source
const (
	ContentTypeJSON               = "application/json"
	ContentTypeXML                = "application/xml"
	ContentTypeXWWWFormURLEncoded = "application/x-www-form-urlencoded"
)

Content Type

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client :

func Fetch

func Fetch(url string, option ...Option) *Client

Fetch :

func (*Client) ToJSON

func (c *Client) ToJSON(i interface{}) error

ToJSON :

func (*Client) ToString

func (c *Client) ToString() (string, error)

ToString :

func (*Client) ToXML

func (c *Client) ToXML(i interface{}) error

ToXML :

type Option

type Option struct {
	ContentType string
	Method      string
	Headers     map[string]string
	Body        interface{}
}

Option :

Jump to

Keyboard shortcuts

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