Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jayin/jhttpserver
A simple http server implement in Java
https://github.com/jayin/jhttpserver
Last synced: 10 days ago
JSON representation
A simple http server implement in Java
- Host: GitHub
- URL: https://github.com/jayin/jhttpserver
- Owner: Jayin
- License: mit
- Created: 2014-03-02T08:24:57.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2015-06-19T15:05:02.000Z (over 9 years ago)
- Last Synced: 2024-04-14T20:12:25.784Z (7 months ago)
- Language: Java
- Homepage:
- Size: 1.88 MB
- Stars: 1
- Watchers: 3
- Forks: 2
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
JHttpServer
-------A simple http server implement in Java, with high-level api.
Feature
-------* suport `GET` `POST` `PUT` `PATCH` `DELETE`
* suport cookie
* support middleware
* support CORS configExample
-------```java
WebServer server = new WebServer();
// regitster a GET router
server.get("/", new Execution() {@Override
public void onExecute(Request req, Response res) {
try {
res.send(new File("./layouts/index.html"));
} catch (IOException e) {
e.printStackTrace();
}}
});// regitster a POST router
server.post("/login", new Execution() {@Override
public void onExecute(Request req, Response res) {
res.setCookie("username","Jayin");
res.setCookie("test","1",0);
res.send("login ok!");
}
});//redirect
server.get("/tolike",new Execution() {
@Override
public void onExecute(Request req, Response res) {
res.redirect("/");
}
});// start the server
server.listen(WebServer.DefaultPort);
}
```now,you can visit `localhost:8000` in you browser
visit `localhost:8000/hello`
or `localhost:8000/like`License
-------MIT