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

@freepi/jsonplaceholder

v3.0.1

Published

Core Library for FreePI package

Downloads

10

Readme

JSONPlaceholder API Wrapper

Description

This is a wrapper for the free JSON Placeholder API. The JSON Placeholder API exists to provide rapid access to dummy JSON data. Documentation for the API itself can be found here.

How To Use

The JSONPlaceholder wrapper abstracts the specific paths for the JSON Placeholder API into easy to use, namespaced methods. It uses Typescript, so parameters and return values are all defined by defualt.

Installation

In your terminal run

$ npm install freepi

# OR

$ npm install @freepi/jsonplaceholder

How To Use

To use the JSONPlaceholder wrapper, import it into your file from either the freepi library or the standalone JSONPlaceholder package.

import { JSONPlaceholder } from 'freepi';

// OR

import JSONPlaceholder from '@freepi/jsonplaceholder';

const jsonPlaceholder = new JSONPlaceholder();

Available Namespaces

JSONPlaceholder has a number of namespaces for each portion of the API. Each one has methods available to it for interacting with that portion of the UI.

  • todos
  • posts
  • comments
  • users
  • albums
  • photos

You can access a namespace and its methods in the following manner:

import { JSONPlaceholder } from 'freepi';

const jsonPlaceholder = new JSONPlaceholder();

// Example: retrieving all todo items
const todos = await jsonPlaceholder.todos.findAll();

Available Methods

Every namespace has the following methods available to it:

  • find: Searches the namespace for a value that matches search parameters,
  • findAll: Gets all values in the namespace,
  • getById: Retrieves a value in the namespace by its id,
  • create: Makes a POST request to the API (JSONPlaceholder imitates a POST request without creating new data),
  • findNested: Retrieve values using the nested url paths available to the API,

Examples:

// find a todo by title
const res = await jsonPlaceholder.todos.find({
  title: 'quo adipisci enim quam ut ab',
});

// Get all post items
const res = await jsonPlaceholder.posts.findAll();

// get a user by id
const res = await jsonPlaceholder.users.getById(1);

// Create a new user
const newUser: User = {
  id: 97,
  name: 'Ian Scott',
  username: 'Uber_Scott',
  email: '[email protected]',
  address: {
    street: 'Apple St',
    suite: 'Suite 333',
    city: 'Nagasaki',
    zipcode: '716-239',
    geo: {
      lat: '65.9817',
      lng: '27.0012',
    },
  },
  phone: '(123)456-7890',
  website: 'IanIsCool.io',
  company: {
    name: 'Green Is Best',
    catchPhrase: 'Waaagh!',
    bs: 'What is bs?',
  },
};

const res = await jsonPlaceholder.users.create(newUser);

// find a nested todo
const res = await jsonPlaceholder.todos.findNested(
  'posts',
  1,
  'comments',
)();

Bug Reports and Feedback

Any bug reports or feedback for this library should be directed to the github issues page