Interface HttpHandler


  • public interface HttpHandler

    Provides a Nitric HTTP function handler. The HttpHandler interface supports pure function development with immutable request and response objects.

    The example below provides a simple Hello World HTTP handler.

    
     package com.example;
    
     import io.nitric.http.HttpHandler;
     import io.nitric.http.HttpRequest;
     import io.nitric.http.HttpResponse;
     import io.nitric.http.HttpServer;
    
     public class Handler implements HttpHandler {
    
         @Override
         public HttpResponse handle(HttpRequest request) {
             return HttpResponse.build("Hello World");
         }
    
         public static void main(String... args) {
             HttpServer().start(new Handler());
         }
     }
     

    These functions return an immutable HttpResponse objects created using the static builder methods.

    See Also:
    HttpRequest, HttpResponse, HttpResponse.Builder
    • Method Detail

      • handle

        HttpResponse handle​(HttpRequest request)
        Handle the HTTP request.
        Parameters:
        request - the HTTP request
        Returns:
        the HTTP response