【发布时间】:2018-10-28 07:43:03
【问题描述】:
如何在不使用node、express等后端技术的情况下创建一个rest api?即:是否可以仅使用客户端框架(如 react、vue)创建 api 而不涉及服务器端?
我想创建一个非常简单的 rest api,我可以将它托管在 github 页面或 gitlab 页面上。
我想要一个可以通过我自己的域(例如 http://username.github.io)访问的 live rest api,而不是你可以使用 json-server 或 My JSON Server 创建的假的 - 并且能够执行以下操作。
这里是api应该做什么的描述。
/quotes.txt - 读取quotes.txt文件的内容并显示出来
/quotes.json - 读取quotes.txt文件的内容并进行转换 转json格式
/random.txt - 读取quotes.txt文件的内容并显示一个 txt格式的随机引用
/random.json - 读取quotes.txt文件的内容并显示一个 json格式的随机引用
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"
}
【问题讨论】:
-
没有后端,您能详细说明一下吗?
标签: json rest api backend static-site