You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
go-library/vendor/gopkg.in/h2non/gentleman.v2/plugins/body
李光春 2100d14a99
update vendor
2 years ago
..
README.md update vendor 2 years ago
body.go update vendor 2 years ago

README.md

gentleman/body Build Status GoDoc API Go Report Card

gentleman's plugin to easy define HTTP bodies. Supports JSON, XML, strings or streams with interface polymorphism.

Installation

go get -u gopkg.in/h2non/gentleman.v2/plugins/body

API

See godoc reference.

Example

package main

import (
  "fmt"
  "gopkg.in/h2non/gentleman.v2"
  "gopkg.in/h2non/gentleman.v2/plugins/body"
)

func main() {
  // Create a new client
  cli := gentleman.New()

  // Define the body we're going to send
  data := map[string]string{"foo": "bar"}
  cli.Use(body.JSON(data))

  // Perform the request
  res, err := cli.Request().Method("POST").URL("http://httpbin.org/post").Send()
  if err != nil {
    fmt.Printf("Request error: %s\n", err)
    return
  }
  if !res.Ok {
    fmt.Printf("Invalid server response: %d\n", res.StatusCode)
    return
  }

  fmt.Printf("Status: %d\n", res.StatusCode)
  fmt.Printf("Body: %s", res.String())
}

License

MIT - Tomas Aparicio