url

package
v2.0.5+incompatible Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2021 License: MIT Imports: 5 Imported by: 0

README

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddPath

func AddPath(path string) p.Plugin

AddPath concatenates a path slice to the existent path in the outgoing request

func BaseURL

func BaseURL(uri string) p.Plugin

BaseURL parses and defines a schema and host URL values in the outgoing request

func Param

func Param(key, value string) p.Plugin

Param replaces one or multiple path param expressions by the given value

func Params

func Params(params map[string]string) p.Plugin

Params replaces one or multiple path param expressions by the given map of key-value pairs

func Path

func Path(path string) p.Plugin

Path defines a new URL path in the outgoing request

func PathPrefix

func PathPrefix(path string) p.Plugin

PathPrefix defines a path prefix to the existent path in the outgoing request

func URL

func URL(uri string) p.Plugin

URL parses and defines a new URL 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