Faker REST API #2272
Replies: 3 comments
-
Thanks for your suggestions, what would be your intended usecase? Do you know of a web server provider that would affordably host this service for an OSS project? Or are you referring to having a template project to host such an API? |
Beta Was this translation helpful? Give feedback.
-
I'm not sure this really needs to be part of the official @faker-js distribution. It's pretty trivial to make a basic web server using your preferred programming language. For example here's an toy implementation in 12 lines using Express: const express = require('express');
const {faker} = require('@faker-js/faker');
const app = express();
const port = 8888;
app.get('/:module/:method', (req, res) => {
try {
res.json(faker[req.params.module][req.params.method]());
} catch (err) {
res.status(500).json({error: "Not a valid method call"});
}
})
app.listen(port, () => console.log(`Listening on port ${port}`)); But to go from this to a full implementation would require a lot of decisions about the structure of the API which are likely to be implementation-specific, as well as figuring out lots of things about hosting.
Realistically most use-cases are much better served by either using the NPM package locally (much faster) or setting up your own server which returns data in the format you need. |
Beta Was this translation helpful? Give feedback.
-
you can checkout fakend.fyi |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Inspiration: JSON-Placeholder
How about a faker REST api much like that of json-placeholder to get fake data
Faker Example
In a similar way faker can also implement a REST API by using the library's methods as REST endpoints
For example, the following fakerjs code
will return the same data as fetching the endpoint:
Beta Was this translation helpful? Give feedback.
All reactions