Skip to content

Instantly share code, notes, and snippets.

@ryanbriones
Created November 23, 2009 07:03
Show Gist options
  • Save ryanbriones/240942 to your computer and use it in GitHub Desktop.
Save ryanbriones/240942 to your computer and use it in GitHub Desktop.
first pass at what my sinatra-like java servlet would look like
import org.sinatraLikeServlet.*;
public class MyApplication extends SinatraLikeHTTPServlet {
@get("/")
public void index(SinatraLikeHTTPServletRequest req
SinatraLikeHTTPServletResponse resp) {
MyResource[] resources = MyResource.findAll();
req.setAttribute("resources", resources);
}
@get("/:id")
public void show(SinatraLikeHTTPServletRequest req
SinatraLikeHTTPServletResponse resp) {
String myResourceId = request.getParameter("id");
MyResource resource = MyResource.find(myResourceId);
req.setAttribute("resource", resource);
}
@get("/:id")
@provides("json")
public String show(SinatraLikeHTTPServletRequest req
SinatraLikeHTTPServletResponse resp) {
String myResourceId = request.getParameter("id");
MyResource resource = MyResource.find(myResourceId);
return resource.toJson();
}
}
@rmanalan
Copy link

Did this ever see the light of day? Would love to be able to use this on a project.

@ryanbriones
Copy link
Author

It didn't actually. This was just a "proposed" API. I showed it to a friend who was more well-versed in Java Servlets and he said he wanted to take a stab at it, but I don't think he ever did. I would love to see this become a reality though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment