back

curl

Transfer data from or to a server, using one of the supported curl protocols

Overview

  • This module wraps the functionality of the curl command line program.

  • It can be used to perform the actions of a web browser, such as downloading webpages and images, submitting webforms and uploading files.

  • It can be used to interface with any web based API.

Form

(curl options)

Arguments

options

A hashmap of options. All available options and their values are described below

Options

OptionDescription
:method
type keyword

    The HTTP method to invoke.

    Can be :GET, :HEAD, :POST, :PUT, :DELETE, :TRACE, :OPTIONS or :PATCH.

    Values are case insensitive.

:url

    The url of the remote service to send the request to.

:headers

    A hashmap of key/value pairs to send as HTTP headers.

:accept

    An HTTP accept header setting.

:form

    A hashmap of key/value pairs to submit as a form submission.

:cookies

    Specify some cookies to send.

:cookie-jar

    Specify a file to use as a cookie jar.

    Can be used to keep a session alive between multiple requests.

:auth

    Authenticate against a web service with the supplied credentials.

:query-params

    Specify a hashmap of key/value pairs to be encoded as GET method query parameters.

:data-raw

    Supply some unformatted data to be sent as the body of a request.

:data-binary

    Supply some binary formatted data to be sent as the body of a request.

:http2

    Use HTTP/2.0 for transport.

:output

    Write the received output to the specified file.

:user-agent

    Supply a custom user agent string for the request.

:decode

    Decode the response body according to its mime type.

:decode-opts

    Specify additional body decoding options.

:success-test

    Specify a custom function to test the returned data type for success or failure.

Examples

Gather the contents of a web page

(curl {:url "https://epiccastle.io"})

Query the Digital Ocean API for a list of droplets

(curl {:url "https://api.digitalocean.com/v2/droplets"
       :headers {:authorization (format "Bearer %s" (System/getenv "DO_TOKEN"))}
       :decode-opts {:key-fn keyword}})