Package dev.gmitch215.bytebox
Class Bytebox
java.lang.Object
dev.gmitch215.bytebox.Bytebox
Builds the platform types a handler returns, and reaches the platform functions that are not
bindings.
public Response fetch(Request request, Env env, ExecutionCtx ctx) {
if (!request.getMethod().equals("GET")) return Bytebox.status(405);
return Bytebox.json("{\"ok\":true}");
}
- Since:
- 1.0.0
-
Method Summary
Modifier and TypeMethodDescriptionstatic ResponseA response carrying bytes.static ResponseA response carrying bytes.static ResponseSends a request to the internet.static ResponseSends a request to the internet.static ResponseSends a request with options.static Headersheaders()Returns a header collection nothing has been put in yet.static ResponseA JSON response built from a JavaScript value, for anything with no codec.static ResponseA 200 carrying already-serialised JSON.static ResponseA JSON response with an explicit status.static <T> ResponseA 200 carrying a Java value as JSON.static voidWrites a line to the Worker's log, whichwrangler tailshows.static org.teavm.jso.typedarrays.ArrayBufferrandom(int bytes) Fills a buffer with cryptographically random bytes.static ResponseA redirect.static RequestBuilds a request, for sending somewhere rather than for answering.static ResponseA 200 carrying text.static ResponseA response with an explicit status.static ResponseA response with a status and headers.static Responsestatus(int status) An empty response with a status, for the cases where the status is the whole answer.static ResponseThe 101 that completes a WebSocket upgrade.static Stringuuid()Returns a cryptographically random UUID.
-
Method Details
-
response
A 200 carrying text.- Parameters:
body- the body- Returns:
- the response
-
response
A response with an explicit status.- Parameters:
body- the bodystatus- the status code- Returns:
- the response
-
response
A response with a status and headers.- Parameters:
body- the bodystatus- the status codeheaders- the headers, as an object of name to value- Returns:
- the response
-
bytes
A response carrying bytes.- Parameters:
body- the bodycontentType- the media type to serve it as- Returns:
- the response
-
bytes
A response carrying bytes.- Parameters:
body- the bodycontentType- the media type to serve it as- Returns:
- the response
-
upgrade
The 101 that completes a WebSocket upgrade.Carries the client end of a pair whose server end the Worker kept. A response with a
webSocketand any other status is refused by the runtime.- Parameters:
client- the client end, fromWebSocketPair.client()- Returns:
- the response
-
json
A 200 carrying already-serialised JSON.- Parameters:
json- the JSON text- Returns:
- the response
-
json
A JSON response with an explicit status.- Parameters:
json- the JSON textstatus- the status code- Returns:
- the response
-
json
A 200 carrying a Java value as JSON.Needs a codec, which the Gradle plugin generates for any type annotated
JSONType.- Type Parameters:
T- the type- Parameters:
value- the valuetype- the value's type- Returns:
- the response
-
json
A JSON response built from a JavaScript value, for anything with no codec.- Parameters:
value- the value- Returns:
- the response
-
status
An empty response with a status, for the cases where the status is the whole answer.- Parameters:
status- the status code- Returns:
- the response
-
redirect
A redirect.- Parameters:
location- where to send the clientstatus- 301, 302, 307 or 308- Returns:
- the response
-
request
Builds a request, for sending somewhere rather than for answering.- Parameters:
url- the URLmethod- the HTTP methodbody- the body, ornullheaders- the headers, ornull- Returns:
- the request
-
fetch
Sends a request to the internet.Counts against the subrequest limit, which is 50 per invocation on the free plan and 10,000 on paid, and against the six simultaneous outgoing connections every plan allows.
- Parameters:
url- the URL- Returns:
- the response
-
fetch
Sends a request to the internet.- Parameters:
request- the request- Returns:
- the response
-
fetch
Sends a request with options.- Parameters:
url- the URLoptions-method,headers,body,cf- Returns:
- the response
-
headers
Returns a header collection nothing has been put in yet.- Returns:
- a header collection nothing has been put in yet
-
uuid
Returns a cryptographically random UUID.- Returns:
- a cryptographically random UUID
-
random
public static org.teavm.jso.typedarrays.ArrayBuffer random(int bytes) Fills a buffer with cryptographically random bytes.- Parameters:
bytes- how many- Returns:
- the bytes
-
log
Writes a line to the Worker's log, whichwrangler tailshows.- Parameters:
message- the message
-