Forge Home

http_request

A task for making HTTP requests.

34,535 downloads

11,269 latest version

5.0 quality score

We run a couple of automated
scans to help you access a
module's quality. Each module is
given a score based on how well
the author has formatted their
code and documentation and
modules are also checked for
malware using VirusTotal.

Please note, the information below
is for guidance only and neither of
these methods should be considered
an endorsement by Puppet.

Version information

  • 0.3.1 (latest)
  • 0.3.0
  • 0.2.2
  • 0.2.1
  • 0.2.0
  • 0.1.0
released Aug 9th 2021
Tasks:
  • http_request

Start using this module

  • r10k or Code Manager
  • Bolt
  • Manual installation
  • Direct download

Add this module to your Puppetfile:

mod 'puppetlabs-http_request', '0.3.1'
Learn more about managing modules with a Puppetfile

Add this module to your Bolt project:

bolt module add puppetlabs-http_request
Learn more about using this module with an existing project

Manually install this module globally with Puppet module tool:

puppet module install puppetlabs-http_request --version 0.3.1

Direct download is not typically how you would use a Puppet module to manage your infrastructure, but you may want to download the module in order to inspect the code.

Download

Documentation

puppetlabs/http_request — version 0.3.1 Aug 9th 2021

http_request

Table of Contents

  1. Description
  2. Requirements
  3. Parameters
  4. Usage

Description

This module includes a task for making HTTP and HTTPS requests.

Requirements

This task requires Ruby to be installed on the target it runs on.

Parameters

base_url

REQUIRED. The fully qualified URL scheme to make requests to.

  • Type: String[1]

body

The request body. If json_endpoint is true, must be able representable as JSON. If json_endpoint is false, must be a string.

  • Type: Optional[Data]

cacert

An absolute path to the CA certificate.

  • Type: Optional[String[1]]

cert

An absolute path to the client certificate.

  • Type: Optional[String[1]]

follow_redirects

If true, automatically follows redirects.

  • Type: Boolean
  • Default: true

headers

A map of headers to add to the payload.

  • Type: Optional[Hash[String, String]]

json_endpoint

If true, parses the request and response bodies as JSON and sets the Content-Type header to application/json.

  • Type: Boolean
  • Default: false

key

An absolute path to the RSA keypair.

  • Type: Optional[String[1]]

max_redirects

The maximum number of redirects to follow when follow_redirects is true.

  • Type: Integer[1]
  • Default: 20

method

The HTTP method to use.

  • Type: Enum[delete, get, post, put, patch]
  • Default: get

path

The path to append to the base_url.

  • Type: Optional[String[1]]

Usage

The only required parameter for the http_request task is url, which is the fully qualified URL scheme to make a request to. By default, the task will make a GET request.

Making a request

The simplest usage of this task is to make a GET request by only setting the url parameter:

  • Unix-like shell command

    $ bolt task run http_request --targets localhost base_url=http://httpbin.org/get
    
  • PowerShell command

    > Invoke-BoltTask -Name 'http_request' -Targets 'localhost' base_url=http://httpbin.org/get
    
  • Plan step

    parameters:
      targets:
        type: TargetSpec
    
    steps:
      - name: request
        task: http_request
        targets: $targets
        parameters:
          base_url: 'http://httpbin.org/get'
    
    return: $request
    

Making a JSON request

If you are making a request to a JSON endpoint, you can configure the task to automatically convert the body to JSON, set the request headers, and parse the response body as JSON. To enable this behavior, set the json_endpoint parameter to true.

  • Unix-like shell command

    $ bolt task run http_request --targets localhost base_url=http://httpbin.org/get json_endpoint=true
    
  • PowerShell command

    > Invoke-BoltTask -Name 'http_request' -Targets 'localhost' base_url=http://httpbin.org/get json_endpoint=true
    
  • Plan step

    parameters:
      targets:
        type: TargetSpec
    
    steps:
      - name: request
        task: http_request
        targets: $targets
        parameters:
          base_url: 'http://httpbin.org/get'
          json_endpoint: true
    
    return: $request.first.value['body']['headers']['User-Agent']
    

Adding headers

You can send custom headers as part of a request using the headers parameter. This parameter accepts a map of header names to values.

To add headers to a request from the command line, pass the headers as JSON to the headers parameter:

  • Unix-like shell command

    $ bolt task run http_request --targets localhost base_url=http://httpbin.org/get headers='{"Content-Type":"application/json"}'
    
  • PowerShell command

    > Invoke-BoltTask -Name 'http_request' -Targets 'localhost' base_url=http://httpbin.org/get headers='{"Content-Type":"application/json"}'
    
  • Plan step

    parameters:
      targets:
        type: TargetSpec
    
    steps:
      - name: request
        task: http_request
        targets: $targets
        parameters:
          base_url: 'http://httpbin.org/get'
          headers:
            Content-Type: application/json
    
    return: $request
    

Adding a body

You can add a body to the request using the body parameter. This parameter accepts a string value. If you need to send data in a specific format, such as JSON, you should format the data before running the task.

To send a body in the request from the command line, pass the data to the body parameter:

  • Unix-like shell command

    $ bolt task run http_request --targets localhost base_url=http://httpbin.org/post method=post body=hello
    
  • PowerShell command

    > Invoke-BoltTask -Name 'http_request' -Targets 'localhost' base_url=http://httpbin.org/post method=post body=hello
    
  • Plan step

    parameters:
      targets:
        type: TargetSpec
    
    steps:
      - name: request
        task: http_request
        targets: $targets
        parameters:
          base_url: 'http://httpbin.org/post'
          method: post
          body: hello
    
    return: $request