Skip to content

Commit 2ca4299

Browse files
committed
A first documentation to README
Add separate sample projects for core and proto
1 parent 19456e7 commit 2ca4299

File tree

21 files changed

+449
-17
lines changed

21 files changed

+449
-17
lines changed

README.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,51 @@
55
# lambda-kotlin-request-router
66

77
A REST request routing layer for AWS lambda handlers written in Kotlin.
8+
9+
## Goal
10+
11+
We came up `lambda-kotlin-request-router` to reduce boilerplate code when implementing a REST API handlers on AWS Lambda.
12+
13+
The library addresses the following aspects:
14+
15+
- serialization and deserialization
16+
- provide useful extensions and abstractions for API Gateway request and response types
17+
- writing REST handlers as functions
18+
- ease implementation of cross cutting concerns for handlers
19+
- ease (local) testing of REST handlers
20+
21+
## Getting Started
22+
23+
To use the core module we need the following:
24+
25+
```groovy
26+
repositories {
27+
maven { url 'https://jitpack.io' }
28+
}
29+
30+
dependencies {
31+
implementation 'com.github.moia-dev.lambda-kotlin-request-router:router:0.3.1'
32+
}
33+
34+
```
35+
36+
Having this we can now go ahead and implement our first handler.
37+
We can implement a request handler as a simple function.
38+
Request and response body are deserialized and serialized for you.
39+
40+
```kotlin
41+
import io.moia.router.Request
42+
import io.moia.router.RequestHandler
43+
import io.moia.router.ResponseEntity
44+
import io.moia.router.Router.Companion.router
45+
46+
class MyRequestHandler : RequestHandler() {
47+
48+
override val router = router {
49+
GET("/some") { r: Request<String> -> ResponseEntity.ok(MyResponse(r.body)) }
50+
}
51+
}
52+
```
53+
54+
55+
File renamed without changes.

sample/build.gradle.kts renamed to samples/lambda-kotlin-request-router-sample-proto/build.gradle.kts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
12
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
2-
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
33
import com.github.jengelman.gradle.plugins.shadow.transformers.Log4j2PluginsCacheFileTransformer
4-
import java.net.URI
5-
import java.util.concurrent.TimeUnit.SECONDS
64
import com.google.protobuf.gradle.protobuf
75
import com.google.protobuf.gradle.protoc
6+
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
7+
import java.net.URI
8+
import java.util.concurrent.TimeUnit.SECONDS
89

910

1011
buildscript {
@@ -59,9 +60,9 @@ tasks {
5960
}
6061

6162
withType<ShadowJar> {
62-
baseName = project.name
63-
classifier = ""
64-
version = ""
63+
archiveBaseName.set(project.name)
64+
archiveClassifier.set("")
65+
archiveVersion.set("")
6566
transform(Log4j2PluginsCacheFileTransformer::class.java)
6667
}
6768

File renamed without changes.
File renamed without changes.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
service: request-router-sample-proto # NOTE: update this with your service name
2+
3+
provider:
4+
name: aws
5+
runtime: java8
6+
region: eu-west-1
7+
8+
package:
9+
artifact: build/libs/lambda-kotlin-request-router-sample-proto.jar
10+
11+
functions:
12+
my-handler:
13+
handler: io.moia.router.sample.MyRequestHandler
14+
events:
15+
- http:
16+
path: some
17+
method: get
18+
- http:
19+
path: some
20+
method: post
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rootProject.name = 'lambda-kotlin-request-router-sample-proto'
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package io.moia.router.sample
2+
3+
import io.moia.router.Request
4+
import io.moia.router.ResponseEntity
5+
import io.moia.router.Router.Companion.router
6+
import io.moia.router.proto.ProtoEnabledRequestHandler
7+
import io.moia.router.proto.sample.SampleOuterClass.Sample
8+
9+
class MyRequestHandler : ProtoEnabledRequestHandler() {
10+
private val controller = SomeController()
11+
12+
override val router = router {
13+
// functions can be externalized...
14+
GET("/some", controller::get)
15+
16+
// simple handlers can also be declared inline
17+
POST("/some") { r: Request<Sample> -> ResponseEntity.ok(r.body) }
18+
}
19+
}

0 commit comments

Comments
 (0)