Class HttpClient

java.lang.Object
io.github.jabrena.juno.api.net.http.HttpClient

public final class HttpClient extends Object
A minimal HTTP/1.1 client recognized as compiler intrinsics by Juno, backed by the Arduino WiFiS3 library's WiFiClient. Requires @Board(ArduinoUnoR4WiFi.class) (the default board) and an active Wifi.begin(String, String) connection.

host/path (and body for post(String, int, String, String, byte[], int, byte[], int, int[]), patch(String, int, String, String, byte[], int, byte[], int, int[]), and query(String, int, String, String, byte[], int, byte[], int, int[])) must each be a compile-time constant: either a string literal, or System.getenv("NAME") of a literal environment-variable name, exactly like Wifi.begin(String, String)'s credentials. Juno has no heap, so none of these can be a runtime-computed String — this also means these methods must be called directly with the literal in hand, never forwarded through another method's own String parameter.

The response body is written into bodyBuffer and the raw response headers into headersBuffer (both caller-owned, fixed-size byte[]), each starting at index 0 and truncated to its own length if longer — pass each buffer's own array length explicitly, since Juno has no runtime .length for an array method parameter. Each method returns the number of body bytes written, or -1 if the connection failed. statusAndHeadersLength (a caller-owned int[2], allocated once outside any loop like the buffers themselves) is filled with the HTTP status code at index 0 (or 0 if the connection failed before a status line was received) and the number of bytes written into headersBuffer at index 1. A request that doesn't complete within a fixed 5-second timeout is abandoned and returns whatever was captured so far.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    A reasonable default size for a caller's body/headers buffer, in bytes.
  • Method Summary

    Modifier and Type
    Method
    Description
    static int
    delete(String host, int port, String path, byte[] bodyBuffer, int bodyBufferLength, byte[] headersBuffer, int headersBufferLength, int[] statusAndHeadersLength)
    Sends a bodyless HTTP DELETE request.
    static int
    get(String host, int port, String path, byte[] bodyBuffer, int bodyBufferLength, byte[] headersBuffer, int headersBufferLength, int[] statusAndHeadersLength)
     
    static int
    patch(String host, int port, String path, String body, byte[] bodyBuffer, int bodyBufferLength, byte[] headersBuffer, int headersBufferLength, int[] statusAndHeadersLength)
    Sends an HTTP PATCH request with a compile-time JSON body.
    static int
    post(String host, int port, String path, String body, byte[] bodyBuffer, int bodyBufferLength, byte[] headersBuffer, int headersBufferLength, int[] statusAndHeadersLength)
     
    static int
    query(String host, int port, String path, String body, byte[] bodyBuffer, int bodyBufferLength, byte[] headersBuffer, int headersBufferLength, int[] statusAndHeadersLength)
    Sends a safe, idempotent HTTP QUERY request with a compile-time JSON body, as defined by RFC 10008.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • DEFAULT_RESPONSE_BUFFER_SIZE

      public static final int DEFAULT_RESPONSE_BUFFER_SIZE
      A reasonable default size for a caller's body/headers buffer, in bytes.
      See Also:
  • Method Details

    • get

      public static int get(String host, int port, String path, byte[] bodyBuffer, int bodyBufferLength, byte[] headersBuffer, int headersBufferLength, int[] statusAndHeadersLength)
    • post

      public static int post(String host, int port, String path, String body, byte[] bodyBuffer, int bodyBufferLength, byte[] headersBuffer, int headersBufferLength, int[] statusAndHeadersLength)
    • delete

      public static int delete(String host, int port, String path, byte[] bodyBuffer, int bodyBufferLength, byte[] headersBuffer, int headersBufferLength, int[] statusAndHeadersLength)
      Sends a bodyless HTTP DELETE request.
    • patch

      public static int patch(String host, int port, String path, String body, byte[] bodyBuffer, int bodyBufferLength, byte[] headersBuffer, int headersBufferLength, int[] statusAndHeadersLength)
      Sends an HTTP PATCH request with a compile-time JSON body.
    • query

      public static int query(String host, int port, String path, String body, byte[] bodyBuffer, int bodyBufferLength, byte[] headersBuffer, int headersBufferLength, int[] statusAndHeadersLength)
      Sends a safe, idempotent HTTP QUERY request with a compile-time JSON body, as defined by RFC 10008.