Skip to content

Commit c2f7cf5

Browse files
committed
Update README
1 parent 2a9193b commit c2f7cf5

File tree

1 file changed

+28
-7
lines changed

1 file changed

+28
-7
lines changed

README.md

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
![Java Express Logo](https://image.ibb.co/mCdxtm/java_express.png)
23

34

@@ -39,6 +40,16 @@ Quick reference:
3940

4041
Every following code can be also found in [this package](https://github.com/Simonwep/java-express/tree/master/src/examples).
4142
# URL Basics
43+
Over the express object you can create handler for all [request-methods](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods) and contexts. Some examples:
44+
```java
45+
app.get("/home", (req, res) -> {
46+
// Will match every request which uses the 'GET' method and matches the '/home' path
47+
});
48+
49+
app.post("/login", (req, res) -> {
50+
// Will match every request which uses the 'POST' method and matches the /login' path
51+
});
52+
```
4253

4354
## URL Parameter
4455
Sometime you want to create dynamic URL where some parts of the URL's are not static.
@@ -172,17 +183,27 @@ Middleware are one of the most important functions of JavaExpress, with middlewa
172183
* `ExpressFilter` - Is **required** to put data on the request listener.
173184
* `ExpressFilterTask` - Can be used for middleware which needs an background thread.
174185

175-
To use an middleware, you simply call:
186+
Middlewares work, for you, exact same as request handler.
187+
For example an middleware for all [request-methods](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods) and contexts:
188+
189+
```java
190+
// Global context, matches every request.
191+
app.use((req, res) -> {
192+
// Handle data
193+
});
194+
```
195+
You can also filter by [request-methods](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods) and contexts:
176196
```java
177197
// Global context, you can also pass an context if you want
178-
app.use(new YourMiddleWare());
198+
app.use("/home", "POST", (req, res) -> {
199+
// Handle request by context '/home' and method 'POST'
200+
});
179201
```
180-
181-
Or create an inline-middleware:
202+
In addition to that yo can use `*` which stands for every **context** or **request method**:
182203
```java
183204
// Global context, you can also pass an context if you want
184-
app.use((req, res) -> {
185-
// Handle data
205+
app.use("/home", "*", (req, res) -> {
206+
// Handle request which matches the context '/home' and all methods.
186207
});
187208
```
188209
## Create own middleware
@@ -278,4 +299,4 @@ app.get("/session", (req, res) -> {
278299

279300
# License
280301

281-
This project is licensed under the MIT License - see the [LICENSE.md](https://choosealicense.com/licenses/mit/) file for details
302+
This project is licensed under the MIT License - see the [LICENSE.md](https://choosealicense.com/licenses/mit/) file for details

0 commit comments

Comments
 (0)