Skip to content

Instantly share code, notes, and snippets.

@yuanmai
Created December 6, 2012 13:35
Show Gist options
  • Save yuanmai/4224484 to your computer and use it in GitHub Desktop.
Save yuanmai/4224484 to your computer and use it in GitHub Desktop.
Ring Hello
(defn app [req]
{:status 200
:headers {"Content-Type" "text/html"}
:body (str "Hi from " (:server-name req))})
(use 'ring.adapter.jetty)
(run-jetty app {:port 8080})
import javax.servlet.http.*;
import javax.servlet.*;
public class HelloServlet extends HttpServlet {
public void doGet (HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
res.setStatus(200);
res.setContentType("text/plain");
PrintWriter out = res.getWriter();
out.println("Hello world");
out.close();
}
}
user> (app {:server-name "localhost"})
{:status 200, :headers {"Content-Type" "text/html"}, :body "Hi from localhost"}
user> (= {:status 200, :headers {"Content-Type" "text/html"}, :body "Hi from localhost"} (app {:server-name "localhost"}))
true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment