Skip to content

fasthttp API - Simplified HTTP client ( inspired by javascript fetch )

License

Notifications You must be signed in to change notification settings

myussufz/fasthttp-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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)

About

fasthttp API - Simplified HTTP client ( inspired by javascript fetch )

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages