Search documentation of jhn_stdlib

# jhn_shttpc (jhn_stdlib v5.10.3)

View Source

A simple HTTP client based on: Hypertext Transfer Protocol (HTTP/1.1): Message Syntax and Routing (rfc7230) Hypertext Transfer Protocol (HTTP/1.1): Semantics and Content (rfc7231) The Hypertext Transfer Protocol Status Code 308 (Permanent Redirect) (rfc7538) PATCH Method for HTTP (rfc5789) HTTP Over TLS (rfc2818)

Options that are available to open/1, open/2 and all HTTP method functions: timeout -> the time in milliseconds the request is allowed to complete limit -> the endtime for the request as system_time in milliseconds headers -> a map of HTTP headers where the headers name can be an atom or binary and the value a binary options -> options to the transport's (tcp or ssl) connection function cacerts -> use jhn_cacerts for the ssl cacerts option allow_wildcard -> allow wildcard certificate matching redirect -> a boolean that determines if redirect are automatically followed for status codes 301, 302, 303, 307, 308 and in the case of 303 use the GET as the method close -> a boolean that determines if the connection should be closed by this client upon completion of the function connection -> if present provides an already established connection to server that will be used for the request

Returned by open/1, open/2 and all HTTP method functions is a map with: status -> {Code, Text} where the code is an integer and Text a binary headers -> a map of HTTP headers from the server reply, recognised names ones are returned as atoms body -> the body of the server reply as a binary, possibly empty connection -> present if neither the server ot the client closed the connection, the value is opaque and should used in later HTTP mehod calls

N.B. The established connections do not time out, if not closed explicitly they will remain and cause a resource leak. For HTTPS requires the ssl OTP lib which is not included in the application resource file. Only supports R18 and later.

# Summary

## Types

connection/0
method/0

## Functions

close(Connection)

Closes an already established connection.

connect(URL)

Performs the CONNECT HTTP method

connect(URL, Opts)

Performs the CONNECT HTTP method

delete(URL)

Performs the DELETE HTTP method

delete(URL, Opts)

Performs the DELET HTTP method

get(URL)

Performs the GET HTTP method

get(URL, Opts)

Performs the GET HTTP method

head(URL)

Performs the HEAD HTTP method

head(URL, Opts)

Performs the HEAD HTTP method

open(URL)

Opens a connection for later use, uses the HTTP HEAD method.

open(URL, Method)

Opens a connection for later use, uses the HTTP Method.

options(URL)

Performs the OPTIONS HTTP method

options(URL, Opts)

Performs the OPTIONS HTTP method

patch(URL, Body)

Performs the PATCH HTTP method

patch(URL, Body, Opts)

Performs the PATCH HTTP method

post(URL, Body)

Performs the POST HTTP method

post(URL, Body, Opts)

Performs the POST HTTP method

put(URL)

Performs the PUT HTTP method

put(URL, Body)

Performs the PUT HTTP method

put(URL, Body, Opts)

Performs the PUT HTTP method

trace(URL)

Performs the TRACE HTTP method

trace(URL, Opts)

Performs the TRACE HTTP method

# Types

# connection/0

    -opaque connection()

# method/0

    -type method() :: 'GET' | 'HEAD' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'CONNECT' | 'OPTIONS' | 'TRACE'.

# Functions

# close(Connection)

    -spec close(connection()) -> ok | {error, _}.

Closes an already established connection.

# connect(URL)

    -spec connect(iodata()) -> map() | {error, _}.

Performs the CONNECT HTTP method

# connect(URL, Opts)

    -spec connect(iodata(), map()) -> map() | {error, _}.

Performs the CONNECT HTTP method

# delete(URL)

    -spec delete(iodata()) -> map() | {error, _}.

Performs the DELETE HTTP method

# delete(URL, Opts)

    -spec delete(iodata(), map()) -> map() | {error, _}.

Performs the DELET HTTP method

# get(URL)

    -spec get(iodata()) -> map() | {error, _}.

Performs the GET HTTP method

# get(URL, Opts)

    -spec get(iodata(), map()) -> map() | {error, _}.

Performs the GET HTTP method

# head(URL)

    -spec head(iodata()) -> map() | {error, _}.

Performs the HEAD HTTP method

# head(URL, Opts)

    -spec head(iodata(), map()) -> map() | {error, _}.

Performs the HEAD HTTP method

# open(URL)

    -spec open(iodata()) -> connection() | {error, _}.

Opens a connection for later use, uses the HTTP HEAD method.

# open(URL, Method)

    -spec open(iodata(), method()) -> connection() | {error, _}.

Opens a connection for later use, uses the HTTP Method.

# options(URL)

    -spec options(iodata()) -> map() | {error, _}.

Performs the OPTIONS HTTP method

# options(URL, Opts)

    -spec options(iodata(), map()) -> map() | {error, _}.

Performs the OPTIONS HTTP method

# patch(URL, Body)

    -spec patch(iodata(), iodata()) -> map() | {error, _}.

Performs the PATCH HTTP method

# patch(URL, Body, Opts)

    -spec patch(iodata(), iodata(), map()) -> map() | {error, _}.

Performs the PATCH HTTP method

# post(URL, Body)

    -spec post(iodata(), iodata()) -> map() | {error, _}.

Performs the POST HTTP method

# post(URL, Body, Opts)

    -spec post(iodata(), iodata(), map()) -> map() | {error, _}.

Performs the POST HTTP method

# put(URL)

    -spec put(iodata()) -> map() | {error, _}.

Performs the PUT HTTP method

# put(URL, Body)

    -spec put(iodata(), iodata()) -> map() | {error, _}.

Performs the PUT HTTP method

# put(URL, Body, Opts)

    -spec put(iodata(), iodata(), map()) -> map() | {error, _}.

Performs the PUT HTTP method

# trace(URL)

    -spec trace(iodata()) -> map() | {error, _}.

Performs the TRACE HTTP method

# trace(URL, Opts)

    -spec trace(iodata(), map()) -> map() | {error, _}.

Performs the TRACE HTTP method