Class | Chef::REST
In: | lib/chef/rest.rb lib/chef/rest/rest_request.rb lib/chef/rest/cookie_jar.rb lib/chef/rest/auth_credentials.rb
Parent: | Object

## Chef::REST

Chef‘s custom REST client with built-in JSON support and RSA signed header authentication.

### Methods

api_request authentication_headers client_name config create_url delete_rest fetch follow_redirect get_rest http_retry_count http_retry_delay new post_rest put_rest register retriable_rest_request run_request sign_requests? signing_key signing_key_filename streaming_request

### Classes and Modules

Class Chef::REST::AuthCredentials
Class Chef::REST::CookieJar
Class Chef::REST::RESTRequest

### Attributes

auth_credentials | [R] |
cookies | [RW] |
redirect_limit | [RW] |
sign_on_redirect | [RW] |
url | [RW] |

### Public Class methods

new(url, client_name=Chef::Config[:node_name], signing_key_filename=Chef::Config[:client_key], options={})

Create a REST client object. The supplied `url` is used as the base for all subsequent requests. For example, when initialized with a base url localhost:4000, a call to `get_rest` with ‘nodes’ will make an HTTP GET request to localhost:4000/nodes

### Public Instance methods

api_request(method, url, headers={}, data=false)

Runs an HTTP request to a JSON API. File Download not supported.

authentication_headers(method, url, json_body=nil)
client_name()
config()
create_url(path)
delete_rest(path, headers={})

Send an HTTP DELETE request to the path

fetch(path, headers={}) {|tmp_file| ...}

Streams a download to a tempfile, then yields the tempfile to a block. After the download, the tempfile will be closed and unlinked. If you rename the tempfile, it will not be deleted. Beware that if the server streams infinite content, this method will stream it until you run out of disk space.

follow_redirect() {|| ...}
get_rest(path, raw=false, headers={})

Send an HTTP GET request to the path

Using this method to `fetch` a file is considered deprecated.

### Parameters

path: | The path to GET
raw: | Whether you want the raw body returned, or JSON inflated. Defaults

      to JSON inflated.

http_retry_count()
http_retry_delay()
post_rest(path, json, headers={})

Send an HTTP POST request to the path

put_rest(path, json, headers={})

Send an HTTP PUT request to the path

register(name=Chef::Config[:node_name], destination=Chef::Config[:client_key])

Register the client

retriable_rest_request(method, url, req_body, headers) {|rest_request| ...}
run_request(method, url, headers={}, data=false, limit=nil, raw=false)

#### DEPRECATED

Use `api_request` instead

sign_requests?()
signing_key()
signing_key_filename()
streaming_request(url, headers) {|tempfile| ...}

Makes a streaming download request. Doesn‘t speak JSON. Streams the response body to a tempfile. If a block is given, it‘s passed to Tempfile.open(), which means that the tempfile will automatically be unlinked after the block is executed.

If no block is given, the tempfile is returned, which means it‘s up to you to unlink the tempfile when you‘re done with it.

[Validate]