svg icon Posts - Docs

The posts endpoint offers a dataset of sample blog post data, including details like titles, body content, user IDs, and tags, useful for testing and prototyping content management and social media features in web applications.

Get all posts

By default you will get 30 items, use Limit and skip to paginate through all items.


          fetch('https://dummyjson.com/posts')
          .then(res => res.json())
          .then(console.log);
        

          {
            "posts": [
              {
                "id": 1,
                "title": "His mother had always taught him",
                "body": "His mother had always taught him not to ever think of himself as better than others. He'd tried to live by this motto. He never looked down on those who were less fortunate or who had less money than him. But the stupidity of the group of people he was talking to made him change his mind.",
                "tags": [
                  "history",
                  "american",
                  "crime"
                ],
                "reactions": {
                  "likes": 192,
                  "dislikes": 25
                },
                "views": 305,
                "userId": 121
              },
              {...},
              {...}
              // 30 items
            ],
            "total": 251,
            "skip": 0,
            "limit": 30
          }
        
Get a single post

          fetch('https://dummyjson.com/posts/1')
          .then(res => res.json())
          .then(console.log);
        

          {
            "id": 1,
            "title": "His mother had always taught him",
            "body": "His mother had always taught him not to ever think of himself as better than others. He'd tried to live by this motto. He never looked down on those who were less fortunate or who had less money than him. But the stupidity of the group of people he was talking to made him change his mind.",
            "tags": [
              "history",
              "american",
              "crime"
            ],
            "reactions": {
              "likes": 192,
              "dislikes": 25
            },
            "views": 305,
            "userId": 121
          }
        
Limit and skip posts

You can pass `limit` and `skip` params to limit and skip the results for pagination, and use `limit=0` to get all items.

You can pass `select` as query params with comma-separated values to select specific data


          fetch('https://dummyjson.com/posts?limit=10&skip=10&select=title,reactions,userId')
          .then(res => res.json())
          .then(console.log);
        

          {
            "posts": [
              {
                "id": 11, // first 10 items are skipped
                "title": "It wasn't quite yet time to panic.",
                "reactions": {
                  "likes": 453,
                  "dislikes": 8
                },
                "userId": 43
              },
              {...},
              {...},
              {...}
              // 10 items
            ],
            "total": 251,
            "skip": 10,
            "limit": 10
          }
        
Sort posts

You can pass `sortBy` and `order` params to sort the results, `sortBy` should be field name and `order` should be "asc" or "desc"


          fetch('https://dummyjson.com/posts?sortBy=title&order=asc')
          .then(res => res.json())
          .then(console.log);
        

          {
            "posts": [
              {
                "id": 141,
                "title": "A judgment that is necessarily hampered", // sorted by title in ascending order
                "userId": 102
                /* rest post data */
              },
              {
                "id": 44,
                "title": "A long black shadow slid across the pavement", // sorted by title in ascending order
                "userId": 124
                /* rest post data */
              },
              {...}
              // 30 items
            ],
            "total": 194,
            "skip": 0,
            "limit": 30
          }
        
Get all posts by user id

          /* getting posts of user with id 5 */
          fetch('https://dummyjson.com/posts/user/5')
          .then(res => res.json())
          .then(console.log);
        

          {
            "posts": [
              {
                "id": 61,
                "title": "I'm going to hire professional help tomorrow.",
                "body": "I'm going to hire professional help tomorrow. I can't handle this anymore. She fell over the coffee table and now there is blood in her catheter. This is much more than I ever signed up to do.",
                "tags": [
                  "fiction",
                  "classic",
                  "american"
                ],
                "reactions": {
                  "likes": 1127,
                  "dislikes": 40
                },
                "views": 4419,
                "userId": 5 // user id is 5
              },
              {...}
            ],
            "total": 2,
            "skip": 0,
            "limit": 2
          }
        
Get post's comments

          /* getting posts of comments with id 1 */
          fetch('https://dummyjson.com/posts/1/comments')
          .then(res => res.json())
          .then(console.log);
        

          {
            "comments": [
              {
                "id": 93,
                "body": "These are fabulous ideas!",
                "postId": 1, // post id is 1
                "likes": 7,
                "user": {
                  "id": 190,
                  "username": "leahw",
                  "fullName": "Leah Gutierrez"
                }
              },
              {...},
              {...}
            ],
            "total": 3,
            "skip": 0,
            "limit": 3
          }
        
Add a new post

Adding a new post will not add it into the server.
It will simulate a POST request and will return the new created post with a new id


          fetch('https://dummyjson.com/posts/add', {
            method: 'POST',
            headers: { 'Content-Type': 'application/json' },
            body: JSON.stringify({
              title: 'I am in love with someone.',
              userId: 5,
              /* other post data */
            })
          })
          .then(res => res.json())
          .then(console.log);
        

          {
            "id": 252,
            "title": "I am in love with someone.",
            "userId": 5
            /* other post data */
          }
        
Update a post

Updating a post will not update it into the server.
It will simulate a PUT/PATCH request and will return updated post with modified data


          /* updating title of post with id 1 */
          fetch('https://dummyjson.com/posts/1', {
            method: 'PUT', /* or PATCH */
            headers: { 'Content-Type': 'application/json' },
            body: JSON.stringify({
              title: 'I think I should shift to the moon',
            })
          })
          .then(res => res.json())
          .then(console.log);
        

          {
            "id": 1,
            "title": "I think I should shift to the moon", // only title was updated
            "body": "His mother had always taught him not to ever think of himself as better than others. He'd tried to live by this motto. He never looked down on those who were less fortunate or who had less money than him. But the stupidity of the group of people he was talking to made him change his mind.",
            "userId": 121,
            "tags": [
              "history",
              "american",
              "crime"
            ],
            "reactions": {
              "likes": 192,
              "dislikes": 25
            }
          }
        
Delete a post

Deleting a post will not delete it into the server.
It will simulate a DELETE request and will return deleted post with `isDeleted` & `deletedOn` keys


          fetch('https://dummyjson.com/posts/1', {
            method: 'DELETE',
          })
          .then(res => res.json())
          .then(console.log);
        

          {
            "id": 1,
            "title": "His mother had always taught him",
            "body": "His mother had always taught him not to ever think of himself as better than others. He'd tried to live by this motto. He never looked down on those who were less fortunate or who had less money than him. But the stupidity of the group of people he was talking to made him change his mind.",
            "tags": [
              "history",
              "american",
              "crime"
            ],
            "reactions": {
              "likes": 192,
              "dislikes": 25
            },
            "views": 305,
            "userId": 121,
            "isDeleted": true,
            "deletedOn": /* ISOTime */
          }
        
Github Github Github