Interface RestRequestConsumer

All Known Subinterfaces:
RestEndpoint
All Known Implementing Classes:
RestEndpointBuilder
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 RestRequestConsumer
The RestRequestConsumer can be coded using the lambda syntax and processes a request for a given locator and for a given HttpMethod. A RestRequestConsumer is invoked with a request of type RestRequestEvent and a response being of type HttpServerResponse. The RestRequestEvent describes the context of the request whereas the HttpServerResponse is used by the lambda expression to prepare the response e.g. via HttpServerResponse.setResponse(Object).
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    onRequest(RestRequestEvent aRequest, org.refcodes.web.HttpServerResponse aResponse)
    The invoker provides a request context being a RestRequestEvent) describing the request and a response being a HttpServerResponse to be processed upon by your lambda's code.
  • Method Details

    • onRequest

      void onRequest(RestRequestEvent aRequest, org.refcodes.web.HttpServerResponse aResponse) throws org.refcodes.web.HttpStatusException
      The invoker provides a request context being a RestRequestEvent) describing the request and a response being a HttpServerResponse to be processed upon by your lambda's code. The method works synchronously and waits (blocks the caller's thread) till it finishes execution.
      Parameters:
      aRequest - The request of type RestRequestEvent describing the request context. Use HttpServerRequest.getRequest(Class) to retrieve the caller's request body or AbstractHttpRequest.getHeaderFields() to retrieve the request's cookies and other Header-Fields.
      aResponse - The response of type HttpServerResponse do be processed upon by the method's implementation. Use HttpServerResponse.setResponse(Object) to provide a response for the client. Use AbstractHttpResponse.getHeaderFields() to set cookies or modify Header-Fields. Throw one of the HttpStatusException sub-types to signal an according erroneous HTTP state.
      Throws:
      org.refcodes.web.HttpStatusException - to be thrown in case something went wrong.