Did you know ... Search Documentation:
Pack prolog_library_collection -- prolog/http_client2.pl
PublicShow source

Alternative to the HTTP client that is part of the SWI-Prolog standard library.

Debugging

The following debug flags are used:

  • http(peek)
  • http(receive_reply)
  • http(send_request)
 http_call(+Uri:or([atom,compound]), :Goal_1) is nondet
 http_call(+Uri:or([atom,compound]), :Goal_1, +Options:options) is nondet
Uses URIs that appear with the ‘next’ keyword in HTTP Link headers to non-deterministically call Goal_1 for all subsequent input streams.

Detects cycles in HTTP Link header referals, in which case the cyclic_link_header/1 is thrown.

Arguments:
Goal_1- The following call is made: `call(Goal_1, In)'.
Options- The following options are supported:
 http_download(+Uri:or([atom,compound])) is det
 http_download(+Uri:or([atom,compound]), +File:atom) is det
http_download(+Uri:or([atom,compound]), -File:atom) is det
 http_download(+Uri:or([atom,compound]), +File:atom, +Options:options) is det
http_download(+Uri:or([atom,compound]), -File:atom, +Options:options) is det
 http_head2(+Uri:atom, +Options:options) is det
 http_header_name_label(+Name:atom, -Label:string) is det
 http_last_modified(+Uri:or([atom,compound]), -Time:float) is det
 http_metadata_content_type(+Metas:list(dict), -MediaType:media_type) is semidet
We cannot expect that an HTTP `Content-Type' header is present:
  • Some HTTP replies have no content.
  • Some non-empty HTTP replies omit the header (probably incorrectly), e.g., `http://abs.270a.info/sparql'.
  • Some Content-Type headers' values do not follow the grammar for Media Types.
 http_metadata_file_name(+Metas:list(dict), -File:atom) is semidet
 http_metadata_final_uri(+Metas:list(dict), -Uri:atom) is det
 http_metadata_last_modified(+Metas:list(dict), -Time:float) is det
 http_metadata_link(+Metas:list(dict), +Relation:atom, -Uri:atom) is semidet
 http_metadata_status(+Metas:list(dict), -Success:between(100,599)) is det
 http_open2(+CurrentUri:or([atom,compound]), -In:istream) is det
 http_open2(+CurrentUri:or([atom,compound]), -In:istream, +Options:options) is det
Alternative to http_open/3 in the SWI standard library with the following additons:
  • Allows Prolog truth/falsity to be bound to HTTP status codes (e.g., Prolog truth = HTTP status code 201 for creation requests). For HTTP status codes that bind to neither truth nor falsity, an exception http_status/1 is thrown.
  • If present, returns the URI that appears in the HTTP Link header with the ‘next’ key. These next URIs must be used in sequent requests in order to retrieve a full result set.
  • Returns full meta-data, including all HTTP headers.
  • Emits detailed, cURL-like debug messages about sent requests and received replies.
Arguments:
Meta- A list of dictionaries, each of which describing an HTTP(S) request/reply interaction as well metadata about the stream.
Options- The following options are supported:
  • accept(+Accept:term) Accept is either a registered file name extension, a Media Type compound term, or a list of Media Type compounds.
  • failure(+Status:or([oneof([warning]),between(400,599)])) Status code that is mapped onto Prolog silent failure. Default is `400'.
  • final_uri(-Uri:atom)
  • metadata(-Metas:list(dict))
  • number_of_hops(+positive_integer) The maximum number of consecutive redirects that is followed. The default is 5.
  • number_of_retries(+positive_integer) The maximum number of times the same HTTP request is retried upon receiving an HTTP error code (i.e., HTTP status codes 400 through 599). The default is 1.
  • status(-between(100,599)) Returns the final status code. When present, options failure/1 and success/1 are not processed.
  • success(+Status:between(200,299)) Status code that is mapped onto Prolog success. Default is `200'.
  • Other options are passed to http_open/3.
 http_status_reason(+Status:between(100,523), +Reason:string) is semidet
http_status_reason(+Status:between(100,523), -Reason:string) is det
http_status_reason(-Status:between(100,523), +Reason:string) is det
http_status_reason(-Status:between(100,523), -Reason:string) is multi
 http_sync(+Uri:or([atom,compound])) is det
 http_sync(+Uri:or([atom,compound]), +File:atom) is det
http_sync(+Uri:or([atom,compound]), -File:atom) is det
 http_sync(+Uri:or([atom,compound]), +File:atom, +Options:options) is det
http_sync(+Uri:or([atom,compound]), -File:atom, +Options:options) is det
Like http_download/[1-3], but does not download File if it already exists.
 curl is det
Enable detailed, cURL-like debug messages.
 nocurl is det
Disable detailed, cURL-like debug messages.

Undocumented predicates

The following predicates are exported, but not or incorrectly documented.

 http_call(Arg1, Arg2, Arg3)
 http_download(Arg1, Arg2)
 http_download(Arg1, Arg2, Arg3)
 http_open2(Arg1, Arg2, Arg3)
 http_sync(Arg1, Arg2)
 http_sync(Arg1, Arg2, Arg3)