Installation
Spider Silk requires Java 21 or later.
Releases are published to GitHub Packages, not to Maven Central.
The current version is 0.1.0-SNAPSHOT.
|
GitHub Packages requires authentication even for public repositories.
Create a personal access token (classic) with the |
Gradle
repositories {
mavenCentral()
maven {
url = uri('https://maven.pkg.github.com/benelog/spider-silk')
credentials {
username = System.getenv('GITHUB_ACTOR')
password = System.getenv('GITHUB_TOKEN') // a PAT with read:packages
}
}
}
dependencies {
implementation 'io.github.benelog.spidersilk:spider-silk-core:0.1.0-SNAPSHOT'
testImplementation 'io.github.benelog.spidersilk:spider-silk-test:0.1.0-SNAPSHOT'
}
Keep the credentials out of the build file by putting them in ~/.gradle/gradle.properties instead, and reading them with findProperty:
gpr.user=your-github-username
gpr.token=ghp_yourPersonalAccessToken
credentials {
username = project.findProperty('gpr.user') ?: System.getenv('GITHUB_ACTOR')
password = project.findProperty('gpr.token') ?: System.getenv('GITHUB_TOKEN')
}
Maven
Declare the repository in pom.xml:
<repositories>
<repository>
<id>github</id>
<url>https://maven.pkg.github.com/benelog/spider-silk</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>io.github.benelog.spidersilk</groupId>
<artifactId>spider-silk-core</artifactId>
<version>0.1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>io.github.benelog.spidersilk</groupId>
<artifactId>spider-silk-test</artifactId>
<version>0.1.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
</dependencies>
The matching credentials go in ~/.m2/settings.xml, under the same id:
<settings>
<servers>
<server>
<id>github</id>
<username>your-github-username</username>
<password>ghp_yourPersonalAccessToken</password>
</server>
</servers>
</settings>
Hello, world
import spidersilk.App;
import spidersilk.WebResponse;
public class Main {
public static void main(String[] args) {
App app = new App();
app.get("/hello/{name}", req -> WebResponse.text("Hello, " + req.pathParam("name")));
app.start(8080);
}
}
$ curl localhost:8080/hello/silk
Hello, silk
Embedded Jetty comes along with spider-silk-core, so nothing else is needed to serve a request.
To run the same app on an embedded Tomcat or Undertow, add spider-silk-tomcat or spider-silk-undertow and see Choosing a server.
To deploy on an external servlet container instead, see Deployment.
Templates render with jte out of the box; FreeMarker, Handlebars, and Thymeleaf are modules of their own, added the same way.