Skip to content

iamdanielyin/req

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

req

A request tool based on Go native net/http.

Getting req

With Go module support, simply add the following import

import "github.com/iamdanielyin/req"

to your code, and then go [build|run|test] will automatically fetch the necessary dependencies.

Otherwise, run the following Go command to install the req package:

$ go get -u github.com/iamdanielyin/req

Running req

First you need to import req package for using req, one simplest example likes the follow example.go:

package main

import (
	"github.com/iamdanielyin/req"
	"log"
)

func main() {
	var posts []struct {
		UserId int    `json:"userId"`
		Id     int    `json:"id"`
		Title  string `json:"title"`
		Body   string `json:"body"`
	}
	if err := req.GET("https://jsonplaceholder.typicode.com/posts", &posts); err != nil {
		log.Fatal(err)
	}
}

And use the Go command to run the demo:

$ go run example.go

List of APIs

  • req.GET(url, dst[, headers])
  • req.POST(url, body, dst[, headers])
  • req.PATCH(url, body, dst[, headers])
  • req.PUT(url, body, dst[, headers])
  • req.DELETE(url, body, dst[, headers])
  • req.CALL(method, url, body, dst[, headers])
  • req.URL(format, values...)
    • .GET(dst[, headers])
    • .POST(body, dst[, headers])
    • .PATCH(body, dst[, headers])
    • .PUT(body, dst[, headers])
    • .DELETE(dst[, headers])
    • .CALL(method, body, dst[, headers])
    • .AddHeader(key, value)
    • .DelHeader(key)
    • .SetHeaders(headers)
    • .SetBody(body)
    • .URL()
    • .Headers()

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages