Skip to content
This repository was archived by the owner on Jun 1, 2023. It is now read-only.

Repository files navigation

PicoHTTP

A lightweight http server

⚠️YOU SHOULD NOT use this library in production due to #2.

Install

Using Gradle
repositories {
//...
maven {
url 'https://maven.thesimpleteam.net/snapshots'
}
}
dependencies {
//...
implementation "net.thesimpleteam:picoHTTP:1.3-SNAPSHOT"
}

Usage

Usage
publicclassServer {
publicstaticvoidmain(String[] args) {
try(PicoHTTPhttp = newPicoHTTP(8080)) {
http.addRoutes(Server.class, newServer());
http.addRoute("/test.js", (client) -> client.send(200, "OK", ContentTypes.JS, "console.log('Hello World')"));
http.run();
while(true) {} //It's a way to avoid closing the server
}
}
//Automatically added@Path("/")
publicvoidhelloWorld(Clientclient) throwsIOException {
client.send(200, "Ok", ContentTypes.PLAIN, "Hello World");
}
@Path(value = "/", method = HTTPMethods.POST)
publicvoidpostExamle(Clientclient) throwsIOException {
Stringdata = client.data();
StringcontentType = client.getHeaders().get("Content-Type");
//Your codeclient.send(501, "Not Implemented");
}
@Path("/hello/\\w+") //Regex examplepublicvoidhelloSomeone(Clientclient) throwsIOException {
Stringname = client.path().split("/")[2]; //When you split the path it should return something like {"", "hello", "(theName)"}client.send(200, "Ok", ContentTypes.PLAIN, "Hello " + name);
}
}

About

A lightweight http server

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages