Build a REST API Using Only Client-Side Tools

How can one design a live REST API using frameworks like React or Vue without any server-side tech? Below is a sample implementation:

# Endpoint: /sayings.txt
messages = [
    "Knowledge rules - Ms Code",
    "Code daily - Dev Spark"
]
print('\n'.join(messages))
# Endpoint: /sayings.json
import json
records = [
    {"text": "Knowledge rules", "author": "Ms Code"},
    {"text": "Code daily", "author": "Dev Spark"}
]
print(json.dumps(records, indent=2))
# Endpoint: /random-saying.txt
import random
msgs = [
    "Knowledge rules - Ms Code",
    "Code daily - Dev Spark"
]
print(random.choice(msgs))
# Endpoint: /random-saying.json
import random, json
record = random.choice([
    {"text": "Knowledge rules", "author": "Ms Code"},
    {"text": "Code daily", "author": "Dev Spark"}
])
print(json.dumps(record, indent=2))

Utilizing client-side only tools to simulate a REST API is possible by taking advantage of static file serving capabilities and client-side routing. Front-end frameworks like React or Vue can be configured to fetch and parse local data files such as JSON documents. This technique works well when the data is relatively static or changes infrequently. Personal projects may benefit from this setup as it eliminates the need for a backend server while still mimicking API endpoints. However, caution is needed if real-time updates or data security become priorities in the project.

hey, you could bundle your data with the client bundle and fetch static json files to mimic endpoints. works well for demo projects, but it wont handle real-time data updates or secure info properly. use with care if scaling up.

hey all, ive been experimentin with servicewok intercepts to mimic api responses from local cache. it kinda simulates a live api on the fly. anyone seen issues with cache updates or similar? would luv to hear ur experince!