https://github.com/fulminazzo/railway
A simple HTTP server that supports dynamic content using Groovy scripts.
https://github.com/fulminazzo/railway
github-actions gradle groovy http
Last synced: about 1 month ago
JSON representation
A simple HTTP server that supports dynamic content using Groovy scripts.
- Host: GitHub
- URL: https://github.com/fulminazzo/railway
- Owner: fulminazzo
- Created: 2024-12-21T22:34:25.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2024-12-23T12:19:31.000Z (over 1 year ago)
- Last Synced: 2025-04-08T22:47:46.162Z (about 1 year ago)
- Topics: github-actions, gradle, groovy, http
- Language: Groovy
- Homepage:
- Size: 177 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
**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/`, where the name parameter will be substituted with one given by the user.
The correspondent **Groovy script** should be located at `/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.