Awesome Open Source
Awesome Open Source

retrosheet 📄

Turn Google Spreadsheet to JSON endpoint. [For Android and JVM].

Benefits 🤗

  • No worries about server health (because you're using Google's server 😋)
  • Rapid response and unlimited bandwidth
  • You can easily migrate to your REST API without any significant code change.
  • You don't have to create an admin panel/dashboard to control the data. You can simply use Google Spreadsheet app (web/mobile).
  • You can use this library to create POC/MVP instantly

Install 🤝


repositories {
  maven { url '' } // Add jitpack

dependencies {
  implementation 'com.github.theapache64:retrosheet:latest.version'

Usage ⌨️

How to write data ? ✍️

Step 1 : Writing Data To Sheet

Step 2

  • Select response destination and select/create a Google sheet to store the responses.

Step 3

  • Now you can open the sheet and change sheet name and column names if you want. This is just to make the Google sheet table look like a real database table (optional)

I've changed to

Step 4

  • Next, Press the Send button and copy the form link

Step 5

  • Now let's go to our code and create our RetrosheetInterceptor
val retrosheetInterceptor = RetrosheetInterceptor.Builder()
    // To Read
        "notes", // sheet name
        "created_at", "title", "description" // columns in same order
    // To write
        "" // form link

Step 6

  • Next, let's create a normal Retrofit API interface
interface NotesApi {

    @Read("SELECT *") 
    @GET("notes") // sheet name
    suspend fun getNotes(): List<Note>

    @POST(ADD_NOTE_ENDPOINT) // form name
    suspend fun addNote(@Body addNoteRequest: AddNoteRequest): AddNoteRequest
  • @Write : To write data to a sheet

  • @Read : To read data from a sheet.

You can lean more about query language from here :

NOTE: You can use your column name in the query rather than using column letter such as A,B,C etc.

How to read data ? 📖

Step 7 : Reading data from Sheet

  • We're done configuring the writing part. Now let's finish the reading part. Create/open a google sheet, (it can be either form connected, or a simple Google sheet).

  • Press Share and copy the link


Step 8

  • Remove contents after the last forward slash from the copied link.

For example, this

would become this

Step 9

  • Finally, Set the Retrofit or OkHttp's baseUrl with the above link.


Done 👍

Full Example 🌟

import com.squareup.moshi.Moshi
import com.github.theapache64.retrosheet.RetrosheetInterceptor
import kotlinx.coroutines.runBlocking
import okhttp3.OkHttpClient
import retrofit2.Retrofit
import retrofit2.converter.moshi.MoshiConverterFactory

 * Created by theapache64 : Jul 21 Tue,2020 @ 02:11
fun main() = runBlocking {
    // Building Retrosheet Interceptor
    val retrosheetInterceptor = RetrosheetInterceptor.Builder()
        // To Read
            "notes", // sheet name
            "created_at", "title", "description" // columns in same order
        // To write
            "" // form link

    // Building OkHttpClient 
    val okHttpClient = OkHttpClient.Builder()
        .addInterceptor(retrosheetInterceptor) // and attaching interceptor

    val moshi = Moshi.Builder().build()

    // Building retrofit client
    val retrofit = Retrofit.Builder()
        // with baseUrl as sheet's public URL    
        .baseUrl("") // Sheet's public URL
        // and attach previously created OkHttpClient

    // Now create the API interface
    val notesApi = retrofit.create(
    // Reading notes

    // Adding note
    val addNote = notesApi.addNote(
        AddNoteRequest("Dynamic Note 1", "Dynamic Desc 1")

Samples 🌠


  • Create an online tool to generate model class from sheet link


This project is applying ktlint (without import ordering since it's conflicted with IDE's format). Before creating a PR, please make sure your code is aligned with ktlint (./gradlew ktlint). We can run auto-format with:

./gradlew ktlintFormat

Author ✍️

  • theapache64

Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
kotlin (3,754
rest-api (568
retrofit (96
okhttp (79
google-sheets (45