Package org.refcodes.rest
Interface RestRequestObserver
-
- All Known Subinterfaces:
RestEndpoint,RestEndpointBuilder
- All Known Implementing Classes:
RestEndpointBuilderImpl
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
@FunctionalInterface public interface RestRequestObserverTheRestRequestObservercan be coded using thelambdasyntax and processes a request for a given locator and for a givenHttpMethod. ARestRequestObserveris invoked with a request of typeRestRequestEventand a response being of typeHttpServerResponse. TheRestRequestEventdescribes the context of the request whereas theHttpServerResponseis used by thelambdaexpression to prepare the response e.g. viaHttpServerResponse.setResponse(Object).
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidonRequest(RestRequestEvent aRequest, org.refcodes.net.HttpServerResponse aResponse)The invoker provides a request context being aRestRequestEvent) describing the request and a response being aHttpServerResponseto be processed upon by yourlambda's code.
-
-
-
Method Detail
-
onRequest
void onRequest(RestRequestEvent aRequest, org.refcodes.net.HttpServerResponse aResponse) throws org.refcodes.net.HttpStatusException
The invoker provides a request context being aRestRequestEvent) describing the request and a response being aHttpServerResponseto be processed upon by yourlambda's code. The method works synchronously and waits (blocks the caller's thread) till it finishes execution.- Parameters:
aRequest- The request of typeRestRequestEventdescribing the request context. UseHttpServerRequest.getRequest(Class)to retrieve the caller's request body orHeaderFieldsAccessor.getHeaderFields()to retrieve the request's cookies and other Header-Fields.aResponse- The response of typeHttpServerResponsedo be processed upon by the method's implementation. UseHttpServerResponse.setResponse(Object)to provide a response for the client. UseHeaderFieldsAccessor.getHeaderFields()to set cookies or modify Header-Fields. Throw one of theHttpStatusExceptionsub-types to signal an according erroneous HTTP state.- Throws:
org.refcodes.net.HttpStatusException- to be thrown in case something went wrong.
-
-