/faker-json-placeholder

Faker JSON Placeholder is a simple fake REST API server for quick testing, prototyping and mocking.

Primary LanguageJavaScriptMIT LicenseMIT

Faker JSON Placeholder


Faker JSON Placeholder is a simple fake REST API server for quick testing, prototyping and mocking.

Why?

When learning a new library, following a tutorial, or building prototypes, many individuals (including myself) are in need of some data.

This simple-to-use Faker JSON API server comes to the rescue in such scenarios by providing you with extensive and configurable JSON fake responses.

You can find it running here and are free to use it in your developments.

I hope you will find it useful.

Is this different from the common JSONPlaceholder?

Think of this as JSONPlaceholder on steroids, providing extensive and configurable JSON fake responses.

Endpoints

Endpoints Query Parameter Response
/api/faker

try it

  • keys
    Specifies the keys you want in your JSON response (comma separated value). e.g: name, age or call a faker function using the double underscore (__) format
    Some syntax sugar below is available for you:

    • name
    • age
    • address
    • email

  • limit
    Specifies the amount of data response you want

  • schema
    Specifies to use one of our predefined schema instead of specifying your own keys

Responds with a list of faker JSON object with the keys specified in the query parameter or using a predefined schema
/api/faker/:id

try it

Responds with a single faker JSON object with the keys specified in the query parameter or using a predefined schema


Calling a faker function

To call a faker function using the keys query parameter, you are to use the double underscore __ format like this <module_name>__<method_name>.

An in-depth overview of the different methods is available in the fakerjs documentation. Below are some of modules available:

Module Example Output
Address address__city Lake Raoulfort
Animal animal__type Dog, cat, snake, bear, lion, etc.
Commerce commerce__product Polo t-shirt
Company company__companyName Zboncak and Sons
Database database__engine MyISAM
Datatype datatype__uuid 7b16dd12-935e-4acc-8381-b1e457bf0176
Date date__past Sat Oct 20 2018 04:19:38 GMT-0700 (Pacific Daylight Time)
Git git__commitMessage feat: add products list page
Hacker hacker__phrase Try to reboot the SQL bus, maybe it will bypass the virtual application!
Image image__avatar https://cloudflare-ipfs.com/ipfs/Qmd3W5DuhgHirLHGVixi6V76LhCkZUz6pnFt5AJBiyvHye/avatar/233.jpg
Internet internet__color #630c7b
Lorem lorem__paragraph Word, words, sentences, slug (lorem-ipsum), paragraph(s), text, lines
Music music__genre R&B
Name name__firstName Cameron
Phone phone__phoneNumber +1 291-299-0192
Random random__locale fr_CA
System system__directoryPath C:\Documents\Newsletters\

Allowing this kind of query parameter opens up a wide range with which you can customize your response.

For more information about the different functions you can check out the official documentation



Predefined Schema

Schema Name Expected Schema Sample
post | posts

(default)

{
  "id": 1,
  "title": "Nihil possimus ut beatae dicta nulla eaque sapiente.",
  "body": "Fuga ea repellendus iste eaque ut sed velit eum consequatur.",
  "userId": 1,
  "createdBy": "Stewart Jaskolski",
  "createdDate": "2022-04-15T15:27:21.885Z"
}
todo | todos
{
  "id": 1,
  "title": "Nobis rem nam et voluptate.",
  "completed": true,
  "userId": 1,
  "completedDate": "2022-04-14T09:19:24.514Z"
}
quote | quotes
{
  "id": 1,
  "body": "Aperiam perspiciatis rerum fugit distinctio.",
  "author": "Abel Leffler",
  "tags": [
    "explicabo",
    "earum",
    "odio"
  ]
}
ecommerce | product | products
{
  "id": 1,
  "name": "Car",
  "description": "New range of formal shirts are designed keeping you in mind. With fits and styling that will make you stand apart",
  "price": "329.00",
  "color": "red",
  "imageURL": "http://loremflickr.com/640/480/abstract"
}
user | users | person
{
  "id": 1,
  "name": "Jim Medhurst",
  "email": "Nolan.Herzog45@gmail.com",
  "address": {
    "street": "272 Kulas Glen",
    "city": "West Elyssachester",
    "zipcode": "68120",
    "geo": {
      "lat": "81.4015",
      "lng": "-98.9926"
    }
  },
  "phone": "(575) 415-0764 x4389",
  "website": "fuzzy-avalanche.org",
  "company": {
    "name": "Collier, Schneider and Kris",
    "bs": "matrix real-time platforms"
  }
}

Credits

This system made use of @faker-js/faker extensively and it was inspired by JSONPlaceholder