https://github.com/theapache64/retrosheet
π Turn Google Spreadsheet to JSON endpoint. Supported Platforms: Android, iOS, JVM and JS. Thanks to Kotlin Multiplatform ππΌ
https://github.com/theapache64/retrosheet
google-sheets interceptors okhttp rest-api retrofit
Last synced: 7 days ago
JSON representation
π Turn Google Spreadsheet to JSON endpoint. Supported Platforms: Android, iOS, JVM and JS. Thanks to Kotlin Multiplatform ππΌ
- Host: GitHub
- URL: https://github.com/theapache64/retrosheet
- Owner: theapache64
- License: apache-2.0
- Created: 2020-07-20T23:25:54.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2025-04-08T18:35:22.000Z (13 days ago)
- Last Synced: 2025-04-14T04:13:03.470Z (7 days ago)
- Topics: google-sheets, interceptors, okhttp, rest-api, retrofit
- Language: Kotlin
- Homepage: https://a64.in/retrosheet
- Size: 24.8 MB
- Stars: 953
- Watchers: 17
- Forks: 42
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- Android-Awesome-Resources - Retrosheet
- awesome-list - theapache64/retrosheet - π Turn Google Spreadsheet to JSON endpoint. Supported Platforms: Android, iOS, JVM and JS. Thanks to Kotlin Multiplatform ππΌ (Kotlin)
README
# π retrosheet
Turn Google Spreadsheet to JSON endpoint.
## π€ Benefits
- π₯ Free analytics via Google forms
- π Migrate to your REST API with minimal code changes.
- π You get a easy to use and real time interface for your data (GoogleSheet) ;)
- πββοΈ Speed up development of your POC or MVP with this library.## π Platform Supported
   
## π€ Install

```kotlin
repositories {
mavenCentral()
}dependencies {
implementation("io.github.theapache64:retrosheet:")
}
```## βοΈ Usage
### βοΈ Writing Data
#### π Step 1: Create a Google Form
Create a form with required fields.
#### π― Step 2: Set Response Destination
Choose a Google Sheet to save responses.

#### π Step 3: Customize Sheet
Rename sheet and columns (optional).

#### π Step 4: Get Form Link
Press `Send` and copy the link.
#### π§ Step 5: Create `RetrosheetConfig` and attach it to the client
```kotlin
val config = RetrosheetConfig.Builder()
.setLogging(true)
// For reading from sheet
.addSheet(
"notes", // sheet name
"created_at", "title", "description" // columns in same order
)
// For writing to sheet
.addForm(
"add_note",
"https://docs.google.com/forms/d/e/1FAIpQLSdmavg6P4eZTmIu-0M7xF_z-qDCHdpGebX8MGL43HSGAXcd3w/viewform?usp=sf_link" // form link
)
.build()val ktorClient = HttpClient {
install(createRetrosheetPlugin(config)) {}
...
}
```#### π Step 6: Create API Interface
```kotlin
interface NotesApi {
@Read("SELECT *")
@GET("notes")
suspend fun getNotes(): List@Write
@POST("add_note")
suspend fun addNote(@Body note: Note): Note
}
```> **@Write** is used for writing data and **@Read** for reading data.
[Query Language Guide](https://developers.google.com/chart/interactive/docs/querylanguage)
### π Reading Data
#### π Step 7: Share Sheet
Open a sheet and copy its shareable link.
#### βοΈ Step 8: Edit Link
Trim the link after the last '/'.`https://docs.google.com/spreadsheets/d/1IcZTH6-g7cZeht_xr82SHJOuJXD_p55QueMrZcnsAvQ`~~/edit?usp=sharing~~
#### π Step 9: Set Base URL
Use the trimmed link as `baseUrl` in `Ktorfit`.```kotlin
val retrofit = Ktorfit.Builder()
// Like this ππΌ
.baseUrl("https://docs.google.com/spreadsheets/d/1YTWKe7_mzuwl7AO1Es1aCtj5S9buh3vKauKCMjx1j_M/")
.httpClient(ktorClient)
.converterFactories(RetrosheetConverter(config))
.build()
```**Done π**
## π Full Example
```kotlin
suspend fun main() {
val notesApi = buildNotesApi()
println(notesApi.getNotes())// Adding sample order
val newNote = notesApi.addNote(
Note(
createdAt = null,
title = "Dynamic Note 1",
description = "DynΓ‘mic Desc 1: ${Date()}"
)
)println(newNote)
}fun createNotesApi(
configBuilder: RetrosheetConfig.Builder.() -> Unit = {}
): NotesApi {
val config = RetrosheetConfig.Builder()
.apply { this.configBuilder() }
.setLogging(true)
// To Read
.addSheet(
"notes", // sheet name
"created_at", "title", "description" // columns in same order
)
// To write
.addForm(
"add_note",
// Google form name
"https://docs.google.com/forms/d/e/1FAIpQLSdmavg6P4eZTmIu-0M7xF_z-qDCHdpGebX8MGL43HSGAXcd3w/viewform?usp=sf_link"
)
.build()val ktorClient = HttpClient {
install(createRetrosheetPlugin(config)) {}
install(ContentNegotiation) {
json()
}
}val retrofit = Ktorfit.Builder()
// GoogleSheet Public URL
.baseUrl("https://docs.google.com/spreadsheets/d/1YTWKe7_mzuwl7AO1Es1aCtj5S9buh3vKauKCMjx1j_M/")
.httpClient(ktorClient)
.converterFactories(RetrosheetConverter(config))
.build()return retrofit.createNotesApi()
}
```
- Source: https://github.com/theapache64/retrosheet-jvm-sample. Check `sample` directory for more samples## π Migration
- Want to migrate from v1 or v2?Here's the [guide](https://github.com/theapache64/retrosheet/blob/master/MIGRATION.md)## Must Read βπΌ
Retrosheet is great for prototyping and not recommended to be used in production for real apps. This is because the library makes direct calls to Google APIsβso if those APIs go down, your app goes down with them.That said, I do use it in production for a few of my [side projects](https://github.com/theapache64/stackzy) :P, and it has been working fine for over 5 years now. (So if things break, Iβll be right there, drowning in tears with you.)
## βοΈ Author
- theapache64