Skip to content

Commit

Permalink
Updated readme and switch to devOS maven
Browse files Browse the repository at this point in the history
  • Loading branch information
LukynkaCZE committed Jun 7, 2024
1 parent 9ed7583 commit f42cf9d
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 23 deletions.
69 changes: 59 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,37 @@

A simple, easy to use and lightweight kotlin web server for small quick projects

## How to Install
## Installation

(I will write this section later once its finished)
<img src="https://cdn.worldvectorlogo.com/logos/kotlin-2.svg" width="16px"></img>
**Kotlin DSL**
```kotlin
repositories {
maven {
name = "devOS"
url = uri("https://mvn.devos.one/releases")
}
}

dependencies {
implementation("cz.lukynka:lkws:1.0")
}
```
<img src="https://github.com/LukynkaCZE/PrettyLog/assets/48604271/3293feca-7395-4100-8b61-257ba40dbe3c" width="18px"></img>
**Gradle Groovy**
```groovy
repositories {
mavenCentral()
maven {
name "devOS"
url "https://mvn.devos.one/releases"
}
}
dependencies {
implementation 'cz.lukynka:lkws:1.0'
}
```
## How to Use

You want to create new instance of `LightweightWebServer` with port supplied as parameter _(defaults to 7270)_
Expand All @@ -21,10 +48,34 @@ server.get("/uwu") { res ->
res.respond("owo :3")
}
```
You can additionally include status code after the response

you can use `Response.URLParameters[param]` to get url parameter

```kotlin
server.get("/teapot") { res ->
res.respond("🫖", 418)
server.put("/users/{USER}/settings") {
val user = it.URLParameters["USER"]
val updatedSettingsJson = it.requestBody
//handle stuff

it.respond("settings changed", 201)
}
```

You can use `Response.requestCookies[cookie]` to get value of cookie. Will return `null` if cookie was not found. To return error to user you can simply throw exception. Error page is customizable (Error Handling section below)

```kotlin
server.post("/projects/create") {
if(it.requestCookies["token"] != superSecretTokenTrustMe) throw Exception("nuh uh, you are not logged in")

val projectName = it.queryParameters["name"]
val redirectAfterCreated = it.queryParameters["redirect"].toBoolean()
//whatever here

if(redirectAfterCreated) {
it.respondRedirect("/projects/$projectName")
} else {
it.respond("project created", 201)
}
}
```

Expand All @@ -33,11 +84,12 @@ You can add Headers by adding `Pair<string, string>`to the `headers` variable of
```kotlin
server.get("/status") { res ->
res.headers.Add(Pair("Content-Type", "application/json"))
res.respondRedirect("{ 'status': 'operational' }")
res.respondJson("{ 'status': 'operational' }")
}
```
---
**⚠️ More request types coming soon ⚠️**

Additionally, this supports all request types (GET, POST, PUT, HEAD, PATCH etc.)

## Error Handling

Expand All @@ -48,6 +100,3 @@ server.error { res ->
res.respond("oopsie happened: ${res.exception}", 500)
}
```

---
**⚠️ There will be more. I am working on it :3 ⚠️**
24 changes: 11 additions & 13 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
`maven-publish`
kotlin("jvm") version "1.9.22"
Expand All @@ -9,23 +7,19 @@ plugins {
group = "cz.lukynka"
version = "1.0"

val githubUser: String = project.findProperty("gpr.user") as String? ?: System.getenv("GITHUB_USER")
val githubPassword: String = project.findProperty("gpr.key") as String? ?: System.getenv("GITHUB_TOKEN")

java.sourceCompatibility = JavaVersion.VERSION_17

repositories {
mavenCentral()
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/LukynkaCZE/PrettyLog")
credentials {username = githubUser; password = githubPassword}
name = "devOS"
url = uri("https://mvn.devos.one/releases")
}
}

dependencies {
testImplementation(kotlin("test"))
implementation("cz.lukynka:pretty-log:1.2.2")
implementation("cz.lukynka:pretty-log:1.3")
}

tasks.test {
Expand All @@ -52,13 +46,17 @@ application {
publishing {
repositories {
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/LukynkaCZE/LKWS")
credentials {username = githubUser; password = githubPassword}
url = uri("https://mvn.devos.one/releases")
credentials {
username = System.getenv()["MAVEN_USER"]
password = System.getenv()["MAVEN_PASS"]
}
}
}

publications {
register<MavenPublication>("gpr") {
register<MavenPublication>("maven") {
groupId = "cz.lukynka"
artifactId = "lkws"
version = version
from(components["java"])
Expand Down
2 changes: 2 additions & 0 deletions src/main/kotlin/Main.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import java.lang.Exception

fun main(args: Array<String>) {
LoggerSettings.loggerStyle = LoggerStyle.BRACKET_PREFIX_WHITE_TEXT
//hello person reading this. I hope you are having a nice day <3
// - maya
}

0 comments on commit f42cf9d

Please sign in to comment.