Skip to content

Commit 2840994

Browse files
authored
Add some examples to README
1 parent a5a86b3 commit 2840994

File tree

1 file changed

+43
-5
lines changed

1 file changed

+43
-5
lines changed

README.md

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@ app.get("/", (req, res) -> {
3838
app.listen(); // Will listen on port 80 which is set as default
3939
```
4040

41-
# Why?
42-
The aim of this project is to allow everybody to create, in a short time, an small and fast HTTP-Server. It's based on [expressjs](https://github.com/expressjs/express) which is really easy to use and also very small and especially fast. The Documentation is currently in progress an will be outsurced when i've got time for this. Therefore any contributions would be great.
43-
4441
# Docs:
4542
* [Routing](#routing)
4643
* [Direct](#direct)
@@ -58,8 +55,7 @@ The aim of this project is to allow everybody to create, in a short time, an sma
5855
* [Create own middleware](#create-own-middleware)
5956
* [Using local variables](#local-variables)
6057
* [License](#license)
61-
62-
Every following code can be also found in [this package](https://github.com/Simonwep/java-express/tree/master/src/examples).
58+
* [Examples](#examples)
6359

6460
# Routing
6561
## Direct
@@ -465,5 +461,47 @@ Example:
465461
app.set("my-data", "Hello World");
466462
app.get("my-data"); // Returns "Hello World"
467463
```
464+
465+
## Examples
466+
### Very simple static-website
467+
```java
468+
469+
// Create instance
470+
new Express() {{
471+
472+
// Define middleware-route for static site
473+
use("/", Middleware.statics("my-website-folder/"));
474+
}};
475+
```
476+
477+
### File download
478+
```java
479+
480+
// Your file
481+
Path downloadFile = Paths.get("my-big-file");
482+
483+
// Create instance
484+
new Express() {{
485+
486+
// Create get-route where the file can be downloaded
487+
get("/download-me", (req, res) -> res.sendAttachment(downloadFile));
488+
}};
489+
```
490+
### Send cookies
491+
```java
492+
new Express() {{
493+
494+
// Define route
495+
get("/give-me-cookies", (req, res) -> {
496+
497+
// Set an cookie (you can call setCookie how often you want)
498+
res.setCookie(new Cookie("my-cookie", "Hello World!"));
499+
500+
// Send text
501+
res.send("Your cookie has been set!");
502+
});
503+
}};
504+
```
505+
468506
# License
469507
This project is licensed under the GNU GPLv3 License - see the [LICENSE](https://github.com/Simonwep/java-express/blob/master/LICENSE) file for details.

0 commit comments

Comments
 (0)