Untitled

 avatar
unknown
plain_text
3 years ago
914 B
9
Indexable
package sparktest;

import static spark.Spark.*;
import spark.Request;
import spark.Response;
import spark.Route;

public class SparkTest {
	
	//http://localhost:8080/hello
	
	public static void main(String[] args) {
		System.setProperty("org.eclipse.jetty.log.announce", "false");
		System.setProperty("org.eclipse.jetty.LEVEL", "OFF");
		
		port(8080);
		
		get("/hello", new Route() {
			@Override
			public Object handle(Request arg0, Response aeg1) throws Exception {
				return "<html><head></head><body><p>Hello, HTTP World!</p></body></html>";
				
			}
		});
		
		get("/stats", new Route() {
			
			public Object handle(Request arg0, Response aeg1) throws Exception {
				Runtime r = Runtime.getRuntime();
				return r.availableProcessors() + r.freeMemory();
			}

		});
		
		
		notFound("<html><head></head><body><h1>404 Not Found</h1></body></html>");
		
		
		}
	}
Editor is loading...