npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

jsonplaceholder

v0.3.3

Published

A simple fake REST API server for testing and prototyping.

Downloads

104

Readme

JSONPlaceholder

JSONPlaceholder is a simple fake REST API for testing and prototyping.

It's like an image placeholder but for web developers.

JSONPlaceholder is powered by JSON Server.

Why?

Most of the time when trying a new library, hacking a prototype or following a tutorial, I found myself in need of some data.

I didn't like the idea of using some public API because I had the feeling that I was spending more time registering a client and understanding a complex API than focusing on my task.

But I liked the idea of image placeholders for web designers. So I decided to code a little Express server inspired by that and here is JSONPlaceholder.

You can find it running here and are free to use it in your developments: http://jsonplaceholder.typicode.com.

Or you can run it locally:

$ npm install -g jsonplaceholder
$ jsonplaceholder

I hope you will find it useful.

Features

  • No registration
  • Zero-config
  • Basic API
  • "Has many" relationships
  • Filters and nested resources
  • Cross-domain (CORS and JSONP)
  • Supports GET, POST, PUT, PATCH, DELETE and OPTIONS verbs
  • Compatible with Backbone, AngularJS, Ember, ...

Available resources

Let's start with resources, JSONPlaceholder provides the usual suspects:

  • Posts http://jsonplaceholder.typicode.com/posts/1
  • Comments http://jsonplaceholder.typicode.com/comments/1
  • Albums http://jsonplaceholder.typicode.com/albums/1
  • Photos http://jsonplaceholder.typicode.com/photos/1
  • Users http://jsonplaceholder.typicode.com/users/1
  • Todos http://jsonplaceholder.typicode.com/todos/1

How to

Here's some code using jQuery showing what can be done with JSONPlaceholder. Since GitHub loads jQuery, you can simply copy and paste these examples in a console.

Showing a resource

$.ajax('http://jsonplaceholder.typicode.com/posts/1', {
  method: 'GET'
}).then(function(data) {
  console.log(data);
});

Listing resources

$.ajax('http://jsonplaceholder.typicode.com/posts', {
  method: 'GET'
}).then(function(data) {
  console.log(data);
});

Creating a resource

// POST adds a random id to the object sent
$.ajax('http://jsonplaceholder.typicode.com/posts', {
  method: 'POST',
  data: {
    title: 'foo',
    body: 'bar',
    userId: 1
  }
}).then(function(data) {
  console.log(data);
});

/* will return
{
  id: 101,
  title: 'foo',
  body: 'bar',
  userId: 1
}
*/

Note: the resource will not be really created on the server but it will be faked as if.

Updating a resource

$.ajax('http://jsonplaceholder.typicode.com/posts/1', {
  method: 'PUT',
  data: {
    id: 1,
    title: 'foo',
    body: 'bar',
    userId: 1
  }
}).then(function(data) {
  console.log(data);
});

/* will return
{
  id: 1
  title: 'foo',
  body: 'bar',
  userId: 1
}
*/
$.ajax('http://jsonplaceholder.typicode.com/posts/1', {
  method: 'PATCH',
  data: {
    title: 'foo'
  }
}).then(function(data) {
  console.log(data);
});

/* will return
{
  id: 1
  title: 'foo',
  body: 'quia et suscipit [...]',
  userId: 1
}
*/

Note: the resource will not be really updated on the server but it will be faked as if.

Deleting a resource

$.ajax('http://jsonplaceholder.typicode.com/posts/1', {
  method: 'DELETE'
});

Note: the resource will not be really deleted on the server but it will be faked as if.

Filtering resources

Basic filtering is supported through query parameters.

// Will return all the posts that belong to the first user
$.ajax('http://jsonplaceholder.typicode.com/posts?userId=1').then(function(data) {
  console.log(data);
});

Nested resources

One level of nested route is available.

$.ajax('http://jsonplaceholder.typicode.com/posts/1/comments').then(function(data) {
  console.log(data);
});
// Which is equivalent to /comments?postId=1

Here's the list of available nested routes:

  • http://jsonplaceholder.typicode.com/posts/1/comments
  • http://jsonplaceholder.typicode.com/albums/1/photos
  • http://jsonplaceholder.typicode.com/users/1/albums
  • http://jsonplaceholder.typicode.com/users/1/todos
  • http://jsonplaceholder.typicode.com/users/1/posts

JSONP request

$.ajax('http://jsonplaceholder.typicode.com/posts/1', {
  dataType: 'jsonp'
}).then(function(data) {
  console.log(data);
});