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/bodytype
李光春 2100d14a99
update vendor
2 years ago
..
README.md update vendor 2 years ago
bodytype.go update vendor 2 years ago

README.md

gentleman/bodytype Build Status GoDoc API Go Report Card

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

Supported type aliases:

  • html - text/html
  • json - application/json
  • xml - application/xml
  • text - text/plain
  • urlencoded - application/x-www-form-urlencoded
  • form - application/x-www-form-urlencoded
  • form-data - application/x-www-form-urlencoded

Installation

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

API

See godoc reference.

Example

package main

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

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

  // Define the JSON data to send 
  data := `{"foo":"bar"}`
  cli.Use(body.String(data))

  // We're sending a JSON based payload
  cli.Use(bodytype.Type("json"))

  // 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