KevanSoon commited on
Commit
514e1e9
·
1 Parent(s): 68aeff7

changed java file

Browse files
Files changed (2) hide show
  1. DemoApplication.java +10 -5
  2. User.java +2 -2
DemoApplication.java CHANGED
@@ -1,13 +1,18 @@
1
- public class DemoApplication {
 
2
 
 
3
  public static void main(String[] args) {
4
- // Hugging Face provides the port via environment variable
5
- int port = Integer.parseInt(System.getenv().getOrDefault("PORT", "8080"));
6
-
7
  Javalin app = Javalin.create().start(port);
8
 
 
 
 
 
9
  app.get("/user", ctx -> {
10
- ctx.json(new User("Kevan", 21));
 
11
  });
12
  }
13
  }
 
1
+ import io.javalin.Javalin;
2
+ import com.google.gson.Gson;
3
 
4
+ public class DemoApplication {
5
  public static void main(String[] args) {
6
+ int port = 8080;
 
 
7
  Javalin app = Javalin.create().start(port);
8
 
9
+ Gson gson = new Gson();
10
+
11
+ app.get("/", ctx -> ctx.result("Hello from Javalin on Hugging Face!"));
12
+
13
  app.get("/user", ctx -> {
14
+ User user = new User("Kevan", 21);
15
+ ctx.result(gson.toJson(user));
16
  });
17
  }
18
  }
User.java CHANGED
@@ -1,6 +1,6 @@
1
  public class User {
2
- public String name;
3
- public int age;
4
 
5
  public User(String name, int age) {
6
  this.name = name;
 
1
  public class User {
2
+ private String name;
3
+ private int age;
4
 
5
  public User(String name, int age) {
6
  this.name = name;