https://github.com/alexsobiek/dash
⚡ High-performance Java HTTP server
https://github.com/alexsobiek/dash
Last synced: 3 months ago
JSON representation
⚡ High-performance Java HTTP server
- Host: GitHub
- URL: https://github.com/alexsobiek/dash
- Owner: alexsobiek
- Created: 2022-04-28T06:32:24.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2022-04-30T05:09:38.000Z (about 3 years ago)
- Last Synced: 2024-12-28T13:43:24.275Z (5 months ago)
- Language: Java
- Homepage:
- Size: 78.1 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# dash
High-performance, multithreaded Java HTTP server written using the Netty framework### ⚠️ WIP
Dash is currently a work in progress and is not production ready. To access full functionality, you'll also have to
depend on Netty since methods in the `HttpRequest` and `HttpResponse` class currently directly expose Netty classes. This will
change by the time of the first release.## Example
[See more](https://github.com/alexsobiek/dash/blob/main/example/src/main/java/com/alexsobiek/dash/example/Server.java)
```java
public class Server {
private final Dash dash;
private final InetSocketAddress address;
private final HttpServer server;public Server() {
dash = new Dash();
address = new InetSocketAddress("localhost", 3000); // bind to localhost:3000
server = dash.createServer(address); // Create HttpServer
server.addHandler(new ExampleHandler()); // Add a handler
listen(); // Start listening for requests
}private void listen() {
server.listen(future -> {
if (future.isSuccess()) System.out.printf("Example HTTP server started on %s\n", address);
else System.out.printf("Failed to start HTTP Server on %s\n", address);
});
}
}class ExampleHandler implements RequestHandler {
@GET(path = "/") // Get requests to "/"
public void onGetRoot(HttpRequest req, HttpResponse res) {
res.writeString("Homepage"); // Write string as response
}
}
```