lambdify.apigateway.Router Maven / Gradle / Ivy
package lambdify.apigateway;
import com.amazonaws.services.lambda.runtime.*;
import lombok.Value;
import lombok.experimental.Accessors;
/**
 * Defines how a router should behave inside an AWS Lambda application.
 *
 * Created by miere.teixeira on 18/04/2018.
 */
public interface Router {
    Entry[] getRoutes();
    /**
     * Defines a Route.
     */
    @Value @Accessors(fluent = true)
    class Route {
        final String url;
        final Methods method;
        public Entry with(LambdaSupplier target ) {
            return new Entry<>( this, target );
        }
        public Entry with( LambdaFunction target ) {
            return new Entry<>( this, target );
        }
        public Entry withNoContent( LambdaConsumer target ) {
            return new Entry<>( this, target );
        }
    }
	/**
	 * Represents a Lambda Function.
	 */
	interface LambdaFunction extends RequestHandler {
		@Override
		default Response handleRequest(Request input, Context context) {
			return invoke(input);
		}
		Response invoke(Request input);
	}
	/**
	 * Represents a Lambda Function that does not produce custom response.
	 */
	interface LambdaConsumer extends LambdaFunction {
	    @Override
	    default Response invoke(Request input) {
	        consume(input);
	        return Response.noContent();
	    }
	    void consume(Request input);
	}
	/**
	 * Represents a Lambda Function that only produce custom responses.
	 */
	interface LambdaSupplier extends LambdaFunction {
	    @Override
	    default Response invoke(Request input) {
	        return supply();
	    }
	    Response supply();
	}
	/**
	 * Represents an Authorizer Function.
	 */
	interface AuthorizerFunction extends RequestHandler {
	}
	/**
	 * A simple holder for Key and Value.
	 *
	 * @param 
	 * @param 
	 */
	@Value @Accessors(fluent = true)
	class Entry {
		final K key;
		final V value;
	}
}
             © 2015 - 2025 Weber Informatics LLC | Privacy Policy