what is httpobjects?

  • a watertight API for implementing JVM code that speaks http(s)
  • implementations of that API for various popular http servers & containers
  • a set of companion libraries for interoperating with various popular JVM libraries

what are the design goals?
  • immutable - everything expressed as pure functions
  • watertight - strives to be a non-leaky abstraction of the http(s) protocol
  • focused - do one thing, do it well
  • performant - suitable for stream processing of very large requests
  • portable - not tied to any other API, works well with popular JVM languages
  • stable - suitable as a foundation for mission-critical components
  • non-blocking - suitable for highly concurrent applications
  • self-documenting - the API documents itself
  • self-contained - core library has no dependencies, works on JDK6 & above
  • compatible - interoperates well with popular JVM languages
how do I get it?

  • git clone && cd httpobjects && mvn install
  • some older versions are available in maven central



    org.httpobjects
    httpobjects
    0.50.0-SNAPSHOT





    org.httpobjects.servlet
    httpobjects-servlet
    0.50.0-SNAPSHOT



    org.httpobjects.jetty
    httpobjects-jetty-7-and-8
    0.50.0-SNAPSHOT



    org.httpobjects.jetty
    httpobjects-jetty-6
    0.50.0-SNAPSHOT



    org.httpobjects.netty
    httpobjects-netty
    0.50.0-SNAPSHOT


   
can I use my servlet/J2EE container?

Yes. First, include the servlet implementation


    org.httpobjects.servlet
    httpobjects-servlet
    0.50.0-SNAPSHOT


Then:

can I use embedded jetty?

Yes. Choose one of the following:


    org.httpobjects.jetty
    httpobjects-jetty-7-and-8
    0.50.0-SNAPSHOT



    org.httpobjects.jetty
    httpobjects-jetty-6
    0.50.0-SNAPSHOT

And then launch the server:

/**
 * Java
 */
import org.httpobjects.*;
import org.httpobjects.jetty.HttpObjectsJettyHandler;

public class Example {
    public static void main(String[] args){

        HttpObject speaker = new HttpObject("/speak"){
            @Override
            public Response get(Request req) {
                return OK(Html("Hello World"));
            }
        };

        HttpObjectsJettyHandler.launchServer(8080, speaker);
    }
}
/**
  * Scala
  */
import org.httpobjects.jetty.HttpObjectsJettyHandler
import org.httpobjects._
import org.httpobjects.DSL._

object Example {
  def main(args: Array[String]) {
    HttpObjectsJettyHandler.launchServer(8080, 
      new HttpObject("/speak"){
        override def get(request:Request) = OK(Html("Hello World"))
      }
    )
  }
}
can I use netty?

Yes. There is a sample netty implementation that you can either use as-is or modify to fit into your existing netty.




    org.httpobjects.netty
    httpobjects-netty
    0.50.0-SNAPSHOT


   

/**
 * Java
 */
import org.httpobjects.*;
import org.httpobjects.netty.HttpobjectsNettySupport;

public class Example {
    public static void main(String[] args){

        HttpObject speaker = new HttpObject("/speak"){
            @Override
            public Response get(Request req) {
                return OK(Html("Hello World"));
            }
        };

        HttpobjectsNettySupport.serve(port, Arrays.asList(speaker));
    }
}

who's responsible for this?
Httpobjects was born as a thought experiment in response to needs at CJ. CJ has also been an early adopter, using httpobjects in a variety of internal projects and generously providing developer time to address bugs and limitations.