body

package
v2.0.3+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 13, 2017 License: MIT Imports: 9 Imported by: 0

README

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func JSON

func JSON(data interface{}) p.Plugin

JSON defines a JSON body in the outgoing request. Supports strings, array of bytes or buffer.

func Reader

func Reader(body io.Reader) p.Plugin

Reader defines a io.Reader stream as request body. Content-Type header won't be defined automatically, you have to declare it manually.

func String

func String(data string) p.Plugin

String defines the HTTP request body based on the given string.

func XML

func XML(data interface{}) p.Plugin

XML defines a XML body in the outgoing request. Supports strings, array of bytes or buffer.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL