View Source jhn_shttpc (jhn_stdlib v5.1.0)

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 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

Functions

Closes an already established connection.

Performs the CONNECT HTTP method

Performs the CONNECT HTTP method

Performs the DELETE HTTP method

Performs the DELET HTTP method

Performs the GET HTTP method

Performs the GET HTTP method

Performs the HEAD HTTP method

Performs the HEAD HTTP method

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

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

Performs the OPTIONS HTTP method

Performs the OPTIONS HTTP method

Performs the PATCH HTTP method

Performs the PATCH HTTP method

Performs the POST HTTP method

Performs the POST HTTP method

Performs the PUT HTTP method

Performs the PUT HTTP method

Performs the PUT HTTP method

Performs the TRACE HTTP method

Performs the TRACE HTTP method

Types

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

Functions

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

Closes an already established connection.

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

Performs the CONNECT HTTP method

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

Performs the CONNECT HTTP method

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

Performs the DELETE HTTP method

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

Performs the DELET HTTP method

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

Performs the GET HTTP method

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

Performs the GET HTTP method

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

Performs the HEAD HTTP method

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

Performs the HEAD HTTP method

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

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

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

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

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

Performs the OPTIONS HTTP method

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

Performs the OPTIONS HTTP method

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

Performs the PATCH HTTP method

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

Performs the PATCH HTTP method

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

Performs the POST HTTP method

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

Performs the POST HTTP method

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

Performs the PUT HTTP method

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

Performs the PUT HTTP method

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

Performs the PUT HTTP method

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

Performs the TRACE HTTP method

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

Performs the TRACE HTTP method