Class BlazingResponse
java.lang.Object
blazing.BlazingResponse
The response used to respond to the client's requests. Contains information
such as query parameters.
@Route
public static void home(BlazingResponse response) {
....
response.sendResponse("hello, world");
}
The snipped above send a response with the text `Hello, World` to the client
that made the request to `/`.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidHelper method for setting up the open CORS for all clients.files()Holds the files parsed from a multipart/form-data formbooleanWhen you make requests with non-simple HTTP methods (e.g., POST, PUT, DELETE), or if you’re sending custom headers (e.g., Authorization), the browser sends an OPTIONS request (preflight) first.Predefined response for the preflight, which sends a 204 header with no body to the client as the Preflight responseparams()Query parameters can be passed with the request without modifying the request path.sendResponse(int statusCode, byte[] responseBytes) Sends a response along with the an array of bytes as a response to a request.voidsendResponse(int status, String data) Responds to the client with text data attached to a status code.voidsendResponse(String data) Responds to the client with text data.voidsendStatus(int status) Sends a status message to the clientvoidsendUiRespose(WebXElement root) Responds to the client with valid mark up that is ready for client side rendering.voidSets response headers for client access.voidstreamFile(String filename, BlazingStreamFunction callback) Streams a file to the client for download purposes, the default content type is "application/octet-stream"response.streamFile("Vid.mp4", (outstream, file) -> { try (FileInputStream fileInputStream = new FileInputStream(file)) { byte[] buffer = new byte[4096]; int bytesRead; while ((bytesRead = fileInputStream.read(buffer)) != -1) { outstream.write(buffer, 0, bytesRead); } outstream.flush(); } catch (FileNotFoundException ex) { BlazingLog.severe(ex.getMessage()); } catch (IOException ex) { BlazingLog.severe(ex.getMessage()); } });voidstreamFile(String filename, String stream_type, BlazingStreamFunction callback) Streams a file to the client for download purposesresponse.streamFile("Archive.zip", "application/zip", (outstream, file) -> { try (FileInputStream fileInputStream = new FileInputStream(file)) { byte[] buffer = new byte[4096]; int bytesRead; while ((bytesRead = fileInputStream.read(buffer)) != -1) { outstream.write(buffer, 0, bytesRead); } outstream.flush(); } catch (FileNotFoundException ex) { BlazingLog.severe(ex.getMessage()); } catch (IOException ex) { BlazingLog.severe(ex.getMessage()); } });voidstreamSizedFile(String filename, BlazingStreamFunction callback) Streams a file with a size that is known upfront.voidstreamSizedFile(String filename, String stream_type, BlazingStreamFunction callback) Streams a file with a size that is known upfront.
-
Constructor Details
-
BlazingResponse
-
-
Method Details
-
getRequestURI
-
params
Query parameters can be passed with the request without modifying the request path. Parameters are stored in the response object.@Route("/users") public static void home(BlazingResponse response) { Map<String, String> params = response.params(); String name = params.get("name"); if (users.contains(name)) { .... } }- Returns:
- Returns a Map of queries issued along with the request by the client.
-
files
-
sendUiRespose
Responds to the client with valid mark up that is ready for client side rendering.
The snipped above response with the Paragraph element with inner text set.response.sendUiResponse( new P("Hello, world") // <p>Hello, world</p> );- Parameters:
root- The root node of the UI response.
-
sendResponse
Responds to the client with text data.
The snipped above response with text data.response.sendResponse("hello 1234");- Parameters:
data- The actual data being sent to the client.
-
sendResponse
Responds to the client with text data attached to a status code.
The snipped above response with text data.response.sendResponse(404, "hello 1234");- Parameters:
status- The status code sent to the clientdata- The actual data being sent to the client.
-
setHeader
-
isPreFlight
public boolean isPreFlight()When you make requests with non-simple HTTP methods (e.g., POST, PUT, DELETE), or if you’re sending custom headers (e.g., Authorization), the browser sends an OPTIONS request (preflight) first. The server needs to respond to this with appropriate CORS headers.- Returns:
-
noContent
Predefined response for the preflight, which sends a 204 header with no body to the client as the Preflight response- Returns:
-
defaultCORSHeaders
public void defaultCORSHeaders()Helper method for setting up the open CORS for all clients. NOTE: Please use this method when testing. When deploying for production please use setHeader and set the appropriate CORS -
sendResponse
Sends a response along with the an array of bytes as a response to a request.- Parameters:
statusCode-responseBytes-- Returns:
-
sendStatus
public void sendStatus(int status) Sends a status message to the clientresponse.sendStatus(404);- Parameters:
status- The status code sent to the client
-
streamFile
Streams a file to the client for download purposes, the default content type is "application/octet-stream"response.streamFile("Vid.mp4", (outstream, file) -> { try (FileInputStream fileInputStream = new FileInputStream(file)) { byte[] buffer = new byte[4096]; int bytesRead; while ((bytesRead = fileInputStream.read(buffer)) != -1) { outstream.write(buffer, 0, bytesRead); } outstream.flush(); } catch (FileNotFoundException ex) { BlazingLog.severe(ex.getMessage()); } catch (IOException ex) { BlazingLog.severe(ex.getMessage()); } });- Parameters:
filename-callback-
-
streamFile
Streams a file to the client for download purposesresponse.streamFile("Archive.zip", "application/zip", (outstream, file) -> { try (FileInputStream fileInputStream = new FileInputStream(file)) { byte[] buffer = new byte[4096]; int bytesRead; while ((bytesRead = fileInputStream.read(buffer)) != -1) { outstream.write(buffer, 0, bytesRead); } outstream.flush(); } catch (FileNotFoundException ex) { BlazingLog.severe(ex.getMessage()); } catch (IOException ex) { BlazingLog.severe(ex.getMessage()); } });- Parameters:
filename-stream_type-callback-
-
streamSizedFile
Streams a file with a size that is known upfront. This is useful for sending small files such as .pdf documents, etc. Sets the content type to "application/octet-stream" as the default value- Parameters:
filename-callback-
-
streamSizedFile
Streams a file with a size that is known upfront. This is useful for sending small files such as .pdf documents, etc.- Parameters:
filename-stream_type-callback-
-