jReflectServer - REST code snippets

Below you'll find some useful REST related code snippets. REST-based services of JReflectServer all respond to GET or POST requests.

 

Getting GET or POST parameters

Use the following code to retrieve request parameters:

String value = request.getParameters().get("test");

 

Access raw http-request / -response

Using raw request and response is a perfect method for writing webservices. Use the WebRequest.getHttpRequest() and WebResponse.getHttpResponse() method to access the low level http components. Please refer to the HttpCore tutorial for information.

If you define a custom response, you need to tell jReflect that you'd like to override the default response using WebResponse.setOverrideHttpReponse(true). Example:

HttpResponse httpResponse = response.getResponse();
StringEntity entity = new StringEntity(
   "This is a result string", ContentType.create("text/plain", "UTF-8"));
httpResponse.setEntity(entity);
httpResponse.setStatusCode(HttpStatus.SC_OK);
// Set override flag
response.setOverrideHttpResponse(true);

 

Note: the code above is the implementation of the convenience method for a text response: WebResponse.text(...):

reponse.text(200, "Hello World!");

 

Blog

BigDecimal (.NET)
An arbitrary large (or small) decimal number implementation for .NET | 8/3/2019

BigDecimal represents a decimal number with arbitrary precision. It is based on a fraction ... Read More

NanoNet - simple Java neural network library
Using backpropagation and sigmoid activation function. | 4/14/2019

NanoNet is a very simple Java neural network library using backpropagation and sigmoid ... Read More

Java async/await nonblocking code library
Write sequential style nonblocking code using a fixed threadpool with Async-Complete for Java | 4/1/2019

Async-Complete (aka Async-Await) is a library for writing asynchronous code in a more ... Read More

More Blog Entries