Skip to content

TensorCraft/RestfulAPIServer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 

Repository files navigation

RestfulAPIServer

A brief and simple Restful API server library in Java

Documentation:

Features:

1.No extra dependencies

This project only used core libraries in jdk and requires no more extra dependencies.

2.Simple

You can start a Restful API server with just several lines of codes like:

public static void main(String[] args) throws IOException {

    int port = 8080;
    String path = "/Web/";

    RestfulAPIServer webserver = new RestfulAPIServer(port);
    webserver.setPath("./web/"); // Set the path for static resources

    webserver.GET("/test", new APIHandler() { // Setup a new API handler for Get requests at "./test"
        @Override
        public void handle(Context context) {
            Map<String, String> params = context.getParams(); // Get the params from the request
            context.Text("Server is running, your params:" + params.toString()); // Respond text to the client
        }
    });

    webserver.start();

    Runtime.getRuntime().addShutdownHook(new Thread(() -> {
        webserver.stop();
    }));
}

3.Efficient

Concurrent requests supported.

Copyright@Tensorcraft

About

A brief and simple Restful API server library in Java

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages