Skip to content

Instantly share code, notes, and snippets.

@dmi3coder
Last active June 3, 2019 10:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmi3coder/f1c612e9c8f922f1c69dee2521092695 to your computer and use it in GitHub Desktop.
Save dmi3coder/f1c612e9c8f922f1c69dee2521092695 to your computer and use it in GitHub Desktop.
Spark app serves method
public class Main {
public static void main(String[] args) {
initApi();
}
public static void initApi() {
port(8080);
get("/", MainResource::handleMain);
}
}
public class MainResource { //In other file
public static Object handleMain(Request request, Response response) {
String htmlCode = "<div>Hello, someone :)</div>";
if (request.attribute("username") != null) {
htmlCode = "<div>Hello, " + request.attribute("username") + ":)</div>";
}
return htmlCode;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment