-6

How do you create a rest api without using any backend technologies such as node, express? ie: Is it possible to create an api using only client side framework such as react, vue and no server side involved?

I would like to create a very simple rest api which I can host either on github pages or gitlab pages.

I would like a live rest api that I can access via my own domain such as http://username.github.io and not a fake one that you can create using json-server or My JSON Server - and would be able to do the following.

Here is the description of what the api should do.

/quotes.txt - Read the contents of the quotes.txt file and display it

/quotes.json - Read the contents of the quotes.txt file and convert it to json format

/random.txt - Read the contents of the quotes.txt file and display a random quote in txt format

/random.json - Read the contents of the quotes.txt file and display a random quote in json format

Output of the API

/quotes.txt

To be or not to be that is the question - Author Unknown
All your dreams can come true if you have the courage to pursue them - Walt Disney
Stand up for what you believe in even if you are standing alone - 

/quotes.json

[
  {
    "quote": "To be or not to be that is the question",
    "author": "Author Unknown"
  },
  {
    "quote": "All your dreams can come true if you have the courage to pursue them",
    "author": "Walt Disney"
  },
  {
    "quote": "Stand up for what you believe in even if you are standing alone",
    "author": ""
  }
]

/random.txt

All your dreams can come true if you have the courage to pursue them - Walt Disney

/random.json

  {
    "quote": "All your dreams can come true if you have the courage to pursue them",
    "author": "Walt Disney"
  }
Ishan
  • 3,931
  • 11
  • 37
  • 59

1 Answers1

1

You could use json-server to serve a JSON file. It supports "canonic" ways to express RESTful requests. This tool can be used on a dev machine or on a intranet server. Here's a blog post about how to set it up.

My JSON Server is a service that does the same exact thing in the Internet environment for you. There are also competing services with similar functionalities, e.g. myjson.com. I'm sure you will find more if you search online.


P.S. I'm sure you'll need to do some massaging to actually translate .txt -> .json. I've never seen services that work against .txt files rather than .json ones.

Ugh. I really like question edits that invalidate the answers.

Igor Soloydenko
  • 11,067
  • 11
  • 47
  • 90