It's a simple demo/test app I've done at the end of 2020. It's a simple API that solves a task described below.
Here are:
- Short 5 minutes demo - https://www.loom.com/share/6738c1f0139c4f68abe9d59625f5e267
- Code walkthrough - https://drive.google.com/file/d/109I797yS8Va3colk-flDSHR15LnfqPPE/view?usp=sharing You can definitely speed it up :)
It's an auto generated API project. Didn't do much clean up, so there are bunch of empty files, auto added gems and configs.
I did couple of assumptions, but in real world there are a places for questions. Commented that out during code walkthrough. Also in some places I've simplified code a bit and in some did an "over kill" just to show the approach. Added comments related to that as well. Haven't added specs as it was a short test for couple of hours and I've pushed it here as is.
The engineering team has been tasked to build a generic Copy API that references copy data that is stored in airtable.
- Each copy data in airtable has a unique
key
that will be passed in the Copy API to get the associated value. - The Copy API will parse the copy value to replace any arbitrary copy placeholders that are given as URL parameters, including formatting them accordingly if there is a format specified in the copy placeholder.
- The Copy API will return a delta of copy data according to a
since
param for the purpose of efficient copy data syncing on the client side.
- Setup an airtable with the following dummy data:
- Create airtable.com account
- Go to https://airtable.com/account and generate & copy the API key
- Go to https://airtable.com and click on
Add a base
from scratch and call itCopy
- Set 2 columns called
Key
andCopy
- Add 3 rows
greeting
,Hi {name}, welcome to {app}!
intro.created_at
,Intro created on {created_at, datetime}
intro.updated_at
,Intro updated on {updated_at, datetime}
- Add a few more rows of your own choosing
- Setup a new ruby on rails backend server
- Add a rake task to import
Copy
base from airtable & save it to a local JSON file (e.g. copy.json) - Load data from the local JSON file (e.g. copy.json) when the backend server starts up
- Setup a
/copy
API endpoint that returns all the copy in JSON format - Setup a
/copy/{key}
API endpoint that returns the correct value associated with the key, for example:/copy/greeting?name=John&app=Bridge
should return{value: 'Hi John, welcome to Bridge!'}
/copy/intro.created_at?created_at=1603814215
should return{value: 'Intro created on Tues Oct 27 3:56:55PM'}
/copy/intro.updated_at?updated_at=1604063144
should return{value: 'Intro updated on Fri Oct 30 1:05:44PM'}
- Setup a
/copy/refresh
API endpoint that fetches latest copy data from airtable and updates the copy data without needing to re-run the rake task & restart the backend server- Start the backend server
- Add a new row
time
,It is {time, datetime}
in airtable - Call
/copy/refresh
to refresh the copy data in the backend server /copy/time?time=1604352707
should return{value: 'It is Mon Nov 2 9:31:47PM'}
- Add
since
param support to/copy
API endpoint that only returns copy data changes after thesince
param.- Hint: this logic shouldn't rely on the data fetched from airtable.
- To demo it working:
- Start the backend server
- Get current epoch time, e.g. go to https://www.epochconverter.com & copy it
- Update data in airtable
- Change
greeting
copy toHello {name}, welcome to {app}!
- Add a new row
bye
,Goodbye
- Change
- Call
/copy/refresh
to refresh the copy data in the backend server /copy?since=<current epoch time>
should only return the updatedgreeting
copy and the newbye
copy and NOTintro.created_at
,intro.updated_at
ortime
copy/copy/greeting?name=John&app=Bridge
should return{value: 'Hello John, welcome to Bridge!'}
/copy/bye
should return{value: 'Goodbye'}
- Record two videos, using Loom.com if possible:
- Showing a working demo
- Walkthrough of the code