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 RestRequestObserver
    The RestRequestObserver can be coded using the lambda syntax and processes a request for a given locator and for a given HttpMethod. A RestRequestObserver 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

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      void onRequest​(RestRequestEvent aRequest, org.refcodes.net.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 Detail

      • onRequest

        void onRequest​(RestRequestEvent aRequest,
                       org.refcodes.net.HttpServerResponse aResponse)
                throws org.refcodes.net.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 HeaderFieldsAccessor.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 HeaderFieldsAccessor.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.net.HttpStatusException - to be thrown in case something went wrong.