# Kotlin Client for PostgREST
Kotlin JVM client for [PostgREST](https://postgrest.org/)



## Installation
Maven
```xml
io.supabase
postgrest-kt
{version}
pom
```
Gradle
```
implementation 'io.supabase:postgrest-kt:{version}'
```
## Usage
### Initializing the client
```kotlin
val postgrestClient = PostgrestDefaultClient(
uri = URI("http://localhost:3111"),
headers = mapOf("Authorization" to "foobar")
)
```
You can also pass in a custom schema using the `schema` parameter.
### Entry points
There are two methods to start any call on the PostgresClient.
#### from
The `from` function is used for querying.
It takes a generic parameter to allow for auto-completion when defining column names.
However, you can always use `Any` if you are unsure about the data type.
```kotlin
postgresClient.from("messages")
.select()
.neq("content", "abc")
.execute()
postgresClient.from("messages")
.select()
.neq(Message::content, "abc")
.execute()
```
#### rpc
The `rpc` function executes a stored procedure.
```kotlin
postgresClient.rpc("get_status", mapOf("foo" to "bar"))
.execute()
```
### Executing requests
There are three ways to execute requests and read the response.
#### execute
The `execute` method returns a [PostgrestHttpResponse](src/main/kotlin/io/supabase/postgrest/http/PostgrestHttpResponse.kt).
The HttpResponse contains the status code, body as string and the count (if you request the count).
```kotlin
val response = postgresClient.from("messages")
.select()
.execute()
println(response.body)
println(response.status)
println(response.count)
```
#### executeAndGetSingle
The `executeAndGetSingle` function returns `T`.
The JSON converter is used to convert the response to the DTO.
```kotlin
data class Message(
val id: Long,
val content: String
)
val message = postgresClient.from("messages")
.select()
.eq(Message::id, 123L)
.limit(1)
.single()
.executeAndGetSingle()
println(message.content)
```
You can also use this function to convert your data to a Map, rather than a separate DTO.
```kotlin
val message = postgresClient.from("messages")
.select()
.eq(Message::id, 123L)
.limit(1)
.single()
.executeAndGetSingle