Here's an example to get a list of fake users:
fetch("https://jsonplaceholder.ir/users")
.then(response => response.json())
.then(json => console.log(json)); // returns an array of users
You can get single resource for any data group by id
property, for example, /users/1
.
Any kind of filtering is doable using query string like /posts?userId=2
or /todos?completed=true
.
One level of nested route is available only for /posts
and /users
data groups, for instance /posts/4/comments
or /users/1/todos
.
CRUD
operations are available for all data groups, that means you can use POST
, GET
, PUT
, DELETE
or other http methods to create, read, update or delete resources, which will be faked as if.
// updating a resource
fetch("https://jsonplaceholder.ir/posts/6", {
method: "PUT",
body: JSON.stringify({ title: "foo", body: "bar", userId: 4 }),
})
.then(response => response.json())
.then(json => console.log(json));
All of the resources are available also with GraphQL, Try out GraphQL Playground for more details.