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"));
// Set override flag


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

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



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

SDCLib/J contribution fork
Contributing to IEEE 11073 SDC Family java webservice stack | 2/2/2019

As former main author of the official project in my last job at SurgiTAIX AG, I will maintain ... Read More

More Blog Entries