Interface Response

All Superinterfaces:
org.teavm.jso.JSObject

public interface Response extends org.teavm.jso.JSObject
An HTTP response, outgoing or received.

Bytebox builds one to return. The reading half matters for a response that came back from a fetch, a service binding or a Durable Object.

Since:
1.0.0
  • Method Summary

    Modifier and Type
    Method
    Description
    default Response
    Throws unless the status is in the 200s, naming the status and the body.
    default org.teavm.jso.typedarrays.ArrayBuffer
    Reads the whole body as bytes.
    Returns the response headers.
    int
    Returns the status code.
    Returns the status text.
    Returns the URL the body came from, which differs from the one asked for after a redirect.
    boolean
    Returns whether the body has already been read.
    boolean
    Returns whether the status is in the 200s.
    default TSObject
    Reads the whole body and parses it as JSON.
    default <T> T
    json(Class<T> type)
    Reads the whole body and converts it to a Java type.
    default <T> T
    json(Function<TSObject,T> mapper)
    Reads the whole body and converts it with a function of your own.
    org.teavm.jso.core.JSPromise<org.teavm.jso.typedarrays.ArrayBuffer>
     
    org.teavm.jso.core.JSPromise<TSObject>
     
    org.teavm.jso.core.JSPromise<org.teavm.jso.core.JSString>
     
    default String
    Reads the whole body as text.

    Methods inherited from interface org.teavm.jso.JSObject

    cast
  • Method Details

    • getStatus

      int getStatus()
      Returns the status code.
      Returns:
      the status code
    • getStatusText

      String getStatusText()
      Returns the status text.
      Returns:
      the status text
    • isOk

      boolean isOk()
      Returns whether the status is in the 200s.
      Returns:
      whether the status is in the 200s
    • getHeaders

      Headers getHeaders()
      Returns the response headers.
      Returns:
      the response headers
    • getUrl

      String getUrl()
      Returns the URL the body came from, which differs from the one asked for after a redirect.
      Returns:
      the URL the body came from, which differs from the one asked for after a redirect
    • isBodyUsed

      boolean isBodyUsed()
      Returns whether the body has already been read.
      Returns:
      whether the body has already been read
    • text

      default String text()
      Reads the whole body as text.
      Returns:
      the decoded body
    • json

      default TSObject json()
      Reads the whole body and parses it as JSON.
      Returns:
      the parsed body
    • bytes

      default org.teavm.jso.typedarrays.ArrayBuffer bytes()
      Reads the whole body as bytes.
      Returns:
      the bytes
    • json

      default <T> T json(Class<T> type)
      Reads the whole body and converts it to a Java type.

      Needs a codec, which the Gradle plugin generates for any type annotated JSONType.

      Type Parameters:
      T - the type
      Parameters:
      type - the type to convert to
      Returns:
      the converted body
    • json

      default <T> T json(Function<TSObject,T> mapper)
      Reads the whole body and converts it with a function of your own.
      Type Parameters:
      T - the type
      Parameters:
      mapper - reads the parsed body
      Returns:
      what the mapper returned
    • assertOk

      default Response assertOk()
      Throws unless the status is in the 200s, naming the status and the body.
      Returns:
      this response
    • readText

      org.teavm.jso.core.JSPromise<org.teavm.jso.core.JSString> readText()
    • readJson

      org.teavm.jso.core.JSPromise<TSObject> readJson()
    • readBytes

      org.teavm.jso.core.JSPromise<org.teavm.jso.typedarrays.ArrayBuffer> readBytes()