Spring Boot backend with RESTful APIs, session management via Supabase
This project demonstrate how to integrate Supabase to a RESTful service built with Spring Boot. This backend plays as a middleware to handle requests from multiple clients via RESTful API then interact with Supabase. The common use case is using this service to public APIs to multiple clients so that each client does not have to interact with Supabase via specific SDK.
Tip
If you want to see the more about Supabase Kotlin Multiplatform samples, check out the supabase-kt repository.
-
Get started with Spring Boot project with Spring Initializr, select Kotlin and Java 17 (JVM)
-
Add dependencies to
build.gradle
val ktor_version = "2.3.10"
implementation("io.ktor:ktor-client-core:$ktor_version")
implementation("io.ktor:ktor-client-java:$ktor_version")
implementation("io.ktor:ktor-client-cio:$ktor_version")
val supabaseVersion = "2.4.0"
implementation(platform("io.github.jan-tennert.supabase:bom:$supabaseVersion"))
implementation("io.github.jan-tennert.supabase:gotrue-kt")
implementation("io.github.jan-tennert.supabase:postgrest-kt")
implementation("io.github.jan-tennert.supabase:storage-kt")
implementation("io.github.jan-tennert.supabase:serializer-jackson:$supabaseVersion")
- Create
SupabaseConfiguration
class to provide Supabase client instance:
@Configuration
class SupabaseConfiguration {
@Bean
fun supabaseClient(): SupabaseClient {
return createSupabaseClient(
supabaseUrl = "SUPABASE_URL",
supabaseKey = "SUPABASE_KEY"
) {
install(Auth)
install(Postgrest)
defaultSerializer = JacksonSerializer()
}
}
}
- Use Supabase Client
@Repository
class ProductRepository(supabase: SupabaseClient) {
...
}
./gradlew run
Service status: http://localhost:8080/actuator/health
Swagger API: http://localhost:8080/swagger-ui/index.html
- Run below command to build the image
./gradlew build && java -jar build/libs/gs-spring-boot-docker-0.1.0.jar
docker build --build-arg JAR_FILE=build/libs/\*.jar -t springio/gs-spring-boot-docker .
- Run the image
docker-compose up