Package dev.gmitch215.bytebox
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 TypeMethodDescriptiondefault ResponseassertOk()Throws unless the status is in the 200s, naming the status and the body.default org.teavm.jso.typedarrays.ArrayBufferbytes()Reads the whole body as bytes.Returns the response headers.intReturns the status code.Returns the status text.getUrl()Returns the URL the body came from, which differs from the one asked for after a redirect.booleanReturns whether the body has already been read.booleanisOk()Returns whether the status is in the 200s.default TSObjectjson()Reads the whole body and parses it as JSON.default <T> TReads the whole body and converts it to a Java type.default <T> TReads 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> readJson()org.teavm.jso.core.JSPromise<org.teavm.jso.core.JSString> readText()default Stringtext()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
Reads the whole body as text.- Returns:
- the decoded body
-
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
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
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
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()
-