bodytype

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2017 License: MIT Imports: 3 Imported by: 0

README

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.v1/plugins/bodytype

API

See godoc reference.

Example

package main

import (
  "fmt"
  "gopkg.in/h2non/gentleman.v1"
  "gopkg.in/h2non/gentleman.v1/plugins/body"
  "gopkg.in/h2non/gentleman.v1/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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Types = map[string]string{
	"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",
}

Types is a map of MIME type aliases

Functions

func Set

func Set(name string) p.Plugin

Set defines an authorization basic header in the outgoing request

Types

This section is empty.

Jump to

Keyboard shortcuts

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