Skip to content

Commit

Permalink
!release
Browse files Browse the repository at this point in the history
First release of the project.
Added support for **dynamic pages** using **Groovy** scripts.
  • Loading branch information
fulminazzo committed Dec 22, 2024
1 parent c727759 commit 445d1dd
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
**Railway** is a simple **HTTP Groovy server** that supports **dynamic page** loading.
It does so by utilizing **Groovy scripts** in the root directory.

Assume the path `/greet/<name>`, where the name parameter will be substituted with one given by the user.

The correspondent **Groovy script** should be located at `<root_directory>/greet.groovy` with contents:

```groovy
import com.sun.net.httpserver.HttpExchange
import it.fulminazzo.railway.ContentHandler
import it.fulminazzo.railway.HTTPCode
static ContentHandler.HTTPResponse handle(HttpExchange httpExchange) {
def path = httpExchange.requestURI.path
def matcher = path =~ /(\/greet\/)([A-Za-z]+)/
if (matcher.find()) return new ContentHandler.HTTPResponse(HTTPCode.OK, matcher.group(1),
"Hello, ${matcher.group(2)}!")
else return new ContentHandler.HTTPResponse(HTTPCode.BAD_REQUEST, path,
"No name provided!"
)
}
```

**NOTE**: this structure is **mandatory**.
The file can be manipulated as the developer pleases,
but a method named **handle** with **parameter `HttpExchange`** and **return type `HTTPResponse`**
will **always** be required.

0 comments on commit 445d1dd

Please sign in to comment.