Skip to content
This repository has been archived by the owner on Jul 6, 2023. It is now read-only.

Latest commit

 

History

History
63 lines (47 loc) · 1.71 KB

groovy_handler.rst

File metadata and controls

63 lines (47 loc) · 1.71 KB

Groovy

Nginx-Clojure is a NGINX module for embedding Clojure or Java or Groovy programs, typically those Ring <ring-clojure/ring/blob/master/SPEC> based handlers.

There are some simple examples about Groovy handler.

Inline Groovy Handler

In nginx.conf

location /groovy {
    handler_type 'groovy';
    handler_code ' 
    import nginx.clojure.java.NginxJavaRingHandler;
    import java.util.Map;
        public class HelloGroovy implements NginxJavaRingHandler {
            public Object[] invoke(Map<String, Object> request){
                return [200, //http status 200
                       ["Content-Type":"text/html"], //headers map
                       "Hello, Groovy & NGINX!"]; //response body can be string, File or Array/Collection of them
            }
        }
    ';
}

External Groovy Handler

In nginx.conf

location /groovy {
    handler_type 'groovy';
    handler_name 'mytest.HelloGroovy';
}

In HelloGroovy.groovy

package mytest;
import nginx.clojure.java.NginxJavaRingHandler;
import java.util.Map;
public class HelloGroovy implements NginxJavaRingHandler {
  public Object[] invoke(Map<String, Object> request){
     return 
     [200,  //http status 200
      ["Content-Type":"text/html"],//headers map
      "Hello, Groovy & NGINX!" //response body can be string, File or Array/Collection of them
      ]; 
  }
}

More details can be found in nginx-clojure.github.io.