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/url/README.md

1.5 KiB

gentleman/url Build Status GoDoc Go Report Card

gentleman's plugin to easily define URL fields in HTTP requests.

Supports full URL parsing, base URL, base path, full path and dynamic path params templating.

Installation

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

API

See godoc reference.

Example

package main

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

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

  // Define the base URL
  cli.Use(url.BaseURL("http://httpbin.org"))

  // Define the path with dynamic value
  cli.Use(url.Path("/:resource"))

  // Define the path value to be replaced
  cli.Use(url.Param("resource", "get"))

  // Perform the request
  res, err := cli.Request().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