This module provides http client functions on JVM and JS.

The downsides of ceylon.net.http.client:

  • Only supports JVM, no JS support.
  • A bit too verbose for simple usage.

Currently only support GET:

switch (result = get("https://example.com"))
case (is String) {
    print("response: status 200, body: ``result``");
}
case (is Integer) {
    print("response: status ``result``");
}

It also provides common request exceptions.
Platform: Java, JavaScript
License: 0BSD
Packages
io.github.weakish.request
Dependencies
ceylon.http.client1.3.0
ceylon.test1.3.0
ceylon.uri1.3.0
Functions
getshared String|Integer get(String url)

Given a Url String, returns GET Response content when success (200), otherwise returns status code.

try_getshared String try_get(String url, Nothing(String) handle_404 = ...)

Like get(), but throws customizable exception on 404, and HttpError for others.

Parameters:
  • handle_404 = throw_404
Throws
Exceptions
ConnectionErrorshared ConnectionError

Network problems such as DNS failure and not connected.

HttpErrorshared HttpError

Thrown if the HTTP request returned an unsuccessful status code. Generally 2xx are sucessful, but your application may have a different meaning of 'success'.

RequestExceptionshared RequestException

Root exception.

TimeoutErrorshared TimeoutError

Thrown if a request times out.

TooManyRedirectsErrorshared TooManyRedirectsError

Thrown if specified number of maximum redirections exceeded.