为您提供一体化的伪造 API
FooApi 简介
我很高兴地宣布我一直在开发的个人项目:fooapi.com。这项服务目前尚未完全完成——一些功能仍在开发中——但我计划在每次发布新版本时分享进展和更新。这个项目的初衷是创建一个统一的平台,让用户可以通过不同的方式访问各种主题的数据。该平台提供涵盖多个类别的真实模拟数据,您可以利用这些数据来模拟您的项目和想法。
您可以在fooapi.com/docs上找到所有详细信息。
如何使用?
目前有两种获取数据的方法:
- REST 端点
- GraphQL 查询
- (您需要 gRPC 吗?)
如果你访问fooapi.com/playground,就可以练习和测试你的查询。
一些有用的例子
以下是一些使用FooApi的实际示例。
1) 您想创建简单的占位符图片吗?很简单:
fooapi.com/imgmaker/700/500/ff0000/000000/foooo
通过此端点,您可以自定义尺寸(宽度和高度)、背景颜色、字体颜色(十六进制格式),并添加自定义消息。
/imgmaker/:width/:height/:bg/:fn/:text
更多详情请参见fooapi.com/docs/images
2) 您想获取数据来测试地图吗?只需使用:
fetch('https://fooapi.com/api/cities?limit=3')
.then(res => res.json())
.then(data => console.log(data))
如果您想知道的话,这个类别的数据是真实的,而不是人为生成的,因为在真实的地图中,我们应该使用实际坐标。
3)一个简单而实用的方法是获取一个随机用户:
fetch('https://fooapi.com/api/users/rand')
.then(res => res.json())
.then(data => console.log(data))
回复:
{
id: "1",
name: "John",
lastname: "Doe",
username: "JohnxDoe11",
birthdate: "1990-01-01",
age: 30,
gender: "Male",
phone: "+63 791 675 8914",
email: "foo@example.com",
country: "USA",
height: 170,
weight: 70
}
4)你是否正在打造下一个社交媒体爆款?请核对:
fetch('https://fooapi.com/api/comments')
.then(res => res.json())
.then(data => console.log(data))
回复:
[
{
id: "1",
comment: "Sunshine and sci-fi sounds like a perfect combo! Enjoy getting lost in your book ",
reactions: 0,
postId: "1",
user: {
id: "50",
name: "John",
lastname: "Smith",
username: "SmiJohnxD100"
}
},
{
id:"2",
comment:"Don't forget the sunscreen! What sci-fi are you reading?",
reactions:1,
postId:"1",
user:{
id:"2",
name:"Akira",
lastname:"Von Trier",
username:"alphaVonAkirax853"
}
}
"28 more elements..."
]
现在您可以自由浏览数据类别了。
你怎么认为?
非常期待您的反馈!请记住,您可以使用此服务来模拟您的应用程序、设计、模型等等。如果您对新的数据类别或功能有任何想法,请在评论区分享。
文章来源:https://dev.to/carban/the-all-in-one-fake-api-for-developers-3hpn

