Last active
June 3, 2019 10:03
-
-
Save dmi3coder/f1c612e9c8f922f1c69dee2521092695 to your computer and use it in GitHub Desktop.
Spark app serves method
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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