Mock API logoMock API

Guide

Mock API is a small fake REST API. It exposes six resources with full CRUD, one-level nested routes, and query filtering. Writes are real: creating, updating, or deleting an item actually changes the in-memory data for as long as the server keeps running.

Base URL: https://mockapi.abdkarim.com

Resources

ResourceBase pathCountDescription
Posts/api/posts100Blog posts, each owned by a user.
Comments/api/comments500Comments left on a post.
Albums/api/albums100Photo albums, each owned by a user.
Photos/api/photos5000Photos belonging to an album.
Todos/api/todos200Todo items, each owned by a user.
Users/api/users10Users of the system.

Routes

Posts

  • GET/api/postsList all items. Supports query filtering.
  • GET/api/posts/:idGet a single item by id.
  • POST/api/postsCreate a new item.
  • PUT/api/posts/:idReplace an item.
  • PATCH/api/posts/:idPartially update an item.
  • DELETE/api/posts/:idDelete an item.
  • GET/api/posts/:id/commentsEquivalent to /api/comments?postId=:id

Comments

  • GET/api/commentsList all items. Supports query filtering.
  • GET/api/comments/:idGet a single item by id.
  • POST/api/commentsCreate a new item.
  • PUT/api/comments/:idReplace an item.
  • PATCH/api/comments/:idPartially update an item.
  • DELETE/api/comments/:idDelete an item.

Albums

  • GET/api/albumsList all items. Supports query filtering.
  • GET/api/albums/:idGet a single item by id.
  • POST/api/albumsCreate a new item.
  • PUT/api/albums/:idReplace an item.
  • PATCH/api/albums/:idPartially update an item.
  • DELETE/api/albums/:idDelete an item.
  • GET/api/albums/:id/photosEquivalent to /api/photos?albumId=:id

Photos

  • GET/api/photosList all items. Supports query filtering.
  • GET/api/photos/:idGet a single item by id.
  • POST/api/photosCreate a new item.
  • PUT/api/photos/:idReplace an item.
  • PATCH/api/photos/:idPartially update an item.
  • DELETE/api/photos/:idDelete an item.

Todos

  • GET/api/todosList all items. Supports query filtering.
  • GET/api/todos/:idGet a single item by id.
  • POST/api/todosCreate a new item.
  • PUT/api/todos/:idReplace an item.
  • PATCH/api/todos/:idPartially update an item.
  • DELETE/api/todos/:idDelete an item.

Users

  • GET/api/usersList all items. Supports query filtering.
  • GET/api/users/:idGet a single item by id.
  • POST/api/usersCreate a new item.
  • PUT/api/users/:idReplace an item.
  • PATCH/api/users/:idPartially update an item.
  • DELETE/api/users/:idDelete an item.
  • GET/api/users/:id/postsEquivalent to /api/posts?userId=:id
  • GET/api/users/:id/albumsEquivalent to /api/albums?userId=:id
  • GET/api/users/:id/todosEquivalent to /api/todos?userId=:id

Query filtering

Any top-level field on a resource can be used as a query parameter for exact-match filtering, e.g. ?userId=1 or ?completed=true. Multiple parameters are combined with AND.

Data & persistence

Data starts from a deterministic seed and lives in memory on the server. POST, PUT, PATCH, and DELETE really mutate that data for the lifetime of the server process — restarting the dev server resets everything back to the seed data.

Examples

Every operation below is demonstrated against the posts resource — the same patterns apply to any of the six resources.

1. Getting a resource

fetch("https://mockapi.abdkarim.com/api/posts/1")
  .then((response) => response.json())
  .then((json) => console.log(json));

// { id: 1, userId: 1, title: "...", body: "..." }

2. Listing all resources

fetch("https://mockapi.abdkarim.com/api/posts")
  .then((response) => response.json())
  .then((json) => console.log(json));

// [{ id: 1, userId: 1, title: "...", body: "..." }, ...] (100 items)

3. Creating a resource

fetch("https://mockapi.abdkarim.com/api/posts", {
  method: "POST",
  body: JSON.stringify({
    title: "foo",
    body: "bar",
    userId: 1,
  }),
  headers: {
    "Content-type": "application/json; charset=UTF-8",
  },
})
  .then((response) => response.json())
  .then((json) => console.log(json));

// { title: "foo", body: "bar", userId: 1, id: 101 }
// This really is added to the in-memory store — GET /api/posts/101 will return it.

4. Updating a resource

fetch("https://mockapi.abdkarim.com/api/posts/1", {
  method: "PUT",
  body: JSON.stringify({
    id: 1,
    title: "foo",
    body: "bar",
    userId: 1,
  }),
  headers: {
    "Content-type": "application/json; charset=UTF-8",
  },
})
  .then((response) => response.json())
  .then((json) => console.log(json));

// { id: 1, title: "foo", body: "bar", userId: 1 }

5. Patching a resource

fetch("https://mockapi.abdkarim.com/api/posts/1", {
  method: "PATCH",
  body: JSON.stringify({
    title: "foo",
  }),
  headers: {
    "Content-type": "application/json; charset=UTF-8",
  },
})
  .then((response) => response.json())
  .then((json) => console.log(json));

// { id: 1, title: "foo", body: "...", userId: 1 }
// Only "title" changes — every other field keeps its previous value.

6. Deleting a resource

fetch("https://mockapi.abdkarim.com/api/posts/1", {
  method: "DELETE",
});

// 204 No Content — GET /api/posts/1 will now return 404.

7. Filtering resources

fetch("https://mockapi.abdkarim.com/api/posts?userId=1")
  .then((response) => response.json())
  .then((json) => console.log(json));

// Only posts where userId equals 1.

8. Listing nested resources

fetch("https://mockapi.abdkarim.com/api/posts/1/comments")
  .then((response) => response.json())
  .then((json) => console.log(json));

// Equivalent to fetch("https://mockapi.abdkarim.com/api/comments?postId=1")