Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/myussufz/fasthttp-api
fasthttp API - Simplified HTTP client ( inspired by javascript fetch )
https://github.com/myussufz/fasthttp-api
client fasthttp fetch go golang json
Last synced: 3 months ago
JSON representation
fasthttp API - Simplified HTTP client ( inspired by javascript fetch )
- Host: GitHub
- URL: https://github.com/myussufz/fasthttp-api
- Owner: myussufz
- License: mit
- Created: 2018-02-23T16:58:08.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2022-06-03T12:23:37.000Z (over 2 years ago)
- Last Synced: 2024-06-19T05:56:51.184Z (8 months ago)
- Topics: client, fasthttp, fetch, go, golang, json
- Language: Go
- Homepage:
- Size: 14.6 KB
- Stars: 7
- Watchers: 4
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
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](https://raw.githubusercontent.com/valyala/fasthttp/master/README.md)
This repo still under development. We accept any pull request. ^\_^
## Installation
```bash
// dependency
$ go get github.com/myussufz/fasthttp-api
$ go get github.com/valyala/fasthttp
```## Quick Start
### Simple Request Method
#### JSON Usage
```go
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
```go
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
```go
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)
```