Module shttpc

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

Copyright © (C) 2015-2020, Jan Henry Nystrom <JanHenryNystrom@gmail.com> -------------------------------------------------------------------

Authors: Jan Henry Nystrom (JanHenryNystrom@gmail.com).

Description

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.

Data Types

connection()

abstract datatype: connection()

method()

method() = 'GET' | 'HEAD' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'CONNECT' | 'OPTIONS' | 'TRACE'

Function Index

close/1 Closes an already established connection.
connect/1 Performs the CONNECT HTTP method.
connect/2 Performs the CONNECT HTTP method.
delete/1 Performs the DELETE HTTP method.
delete/2 Performs the DELET HTTP method.
get/1 Performs the GET HTTP method.
get/2 Performs the GET HTTP method.
head/1 Performs the HEAD HTTP method.
head/2 Performs the HEAD HTTP method.
open/1 Opens a connection for later use, uses the HTTP HEAD method.
open/2 Opens a connection for later use, uses the HTTP Method.
options/1 Performs the OPTIONS HTTP method.
options/2 Performs the OPTIONS HTTP method.
patch/2 Performs the PATCH HTTP method.
patch/3 Performs the PATCH HTTP method.
post/2 Performs the POST HTTP method.
post/3 Performs the POST HTTP method.
put/1 Performs the PUT HTTP method.
put/2 Performs the PUT HTTP method.
put/3 Performs the PUT HTTP method.
trace/1 Performs the TRACE HTTP method.
trace/2 Performs the TRACE HTTP method.

Function Details

close/1

close(Connection::connection()) -> ok | {error, term()}

Closes an already established connection.

connect/1

connect(URL::iodata()) -> map() | {error, term()}

Performs the CONNECT HTTP method

connect/2

connect(URL::iodata(), Opts::map()) -> map() | {error, term()}

Performs the CONNECT HTTP method

delete/1

delete(URL::iodata()) -> map() | {error, term()}

Performs the DELETE HTTP method

delete/2

delete(URL::iodata(), Opts::map()) -> map() | {error, term()}

Performs the DELET HTTP method

get/1

get(URL::iodata()) -> map() | {error, term()}

Performs the GET HTTP method

get/2

get(URL::iodata(), Opts::map()) -> map() | {error, term()}

Performs the GET HTTP method

head/1

head(URL::iodata()) -> map() | {error, term()}

Performs the HEAD HTTP method

head/2

head(URL::iodata(), Opts::map()) -> map() | {error, term()}

Performs the HEAD HTTP method

open/1

open(URL::iodata()) -> connection() | {error, term()}

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

open/2

open(URL::iodata(), Method::method()) -> connection() | {error, term()}

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

options/1

options(URL::iodata()) -> map() | {error, term()}

Performs the OPTIONS HTTP method

options/2

options(URL::iodata(), Opts::map()) -> map() | {error, term()}

Performs the OPTIONS HTTP method

patch/2

patch(URL::iodata(), Body::iodata()) -> map() | {error, term()}

Performs the PATCH HTTP method

patch/3

patch(URL::iodata(), Body::iodata(), Opts::map()) -> map() | {error, term()}

Performs the PATCH HTTP method

post/2

post(URL::iodata(), Body::iodata()) -> map() | {error, term()}

Performs the POST HTTP method

post/3

post(URL::iodata(), Body::iodata(), Opts::map()) -> map() | {error, term()}

Performs the POST HTTP method

put/1

put(URL::iodata()) -> map() | {error, term()}

Performs the PUT HTTP method

put/2

put(URL::iodata(), Body::iodata()) -> map() | {error, term()}

Performs the PUT HTTP method

put/3

put(URL::iodata(), Body::iodata(), Opts::map()) -> map() | {error, term()}

Performs the PUT HTTP method

trace/1

trace(URL::iodata()) -> map() | {error, term()}

Performs the TRACE HTTP method

trace/2

trace(URL::iodata(), Opts::map()) -> map() | {error, term()}

Performs the TRACE HTTP method


Generated by EDoc