Skip to content

Latest commit

 

History

History
82 lines (67 loc) · 2.9 KB

README.md

File metadata and controls

82 lines (67 loc) · 2.9 KB

supa-spring-kt

Spring Boot backend with RESTful APIs, session management via Supabase Screenshot 2024-06-05 at 00 07 52

⭐️ About

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.

⚙️ Setup

  1. Get started with Spring Boot project with Spring Initializr, select Kotlin and Java 17 (JVM)

  2. 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")
  1. 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()
        }
    }
}
  1. Use Supabase Client
@Repository
class ProductRepository(supabase: SupabaseClient) {
    ...
}

📒 API docs & Supabase schema

API Docs

Screenshot 2024-06-23 at 19 29 54

Schema

Screenshot 2024-06-04 at 23 16 08

👨‍💻 Run

./gradlew run

Service status: http://localhost:8080/actuator/health

Swagger API: http://localhost:8080/swagger-ui/index.html

With Docker

  1. 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 .
  1. Run the image
docker-compose up