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

@holidayextras/jsonapi-client

v1.0.0

Published

A clientside module designed to make it really easy to consume a json:api service.

Downloads

102

Readme

Coverage Status Build Status Code Climate Codacy Badge Dependencies Status

jsonapi-client

A javascript module designed to make it really easy to consume a json:api service.

!! THIS PROJECT IS NOT IN NPM !!

$ npm install --save jsonapi-client@holidayextras/jsonapi-client

note: this project requires a Node.js version of at least 4.5.0.

Motivation / Justification / Rationale

Consuming a json:api service from within Javascript is a non-trivial affair. Setting up a transport mechanism, authentication, making requests to standardised HTTP routes, error handling, pagination and expanding an inclusion tree... All of these things represent barriers to consuming an API. This module takes away all the hassle and lets developers focus on interacting with a rich API without wasting developer time focusing on anything other than shipping valuable features.

This module is tested against the example json:api server provided by jsonapi-server.

Full documentation

The tl;dr

In a browser

<script src="/dist/jsonapi-client.min.js"></script>
<script type="text/javascript">
  var client = new JsonapiClient("http://localhost:16006/rest", {
    header: {
      authToken: "2ad1d6f7-e1d0-480d-86b2-dfad8af4a5b3"
    }
  });
</script>

Creating a new Client

var JsonapiClient = require("jsonapi-client");
var client = new JsonapiClient("http://localhost:16006/rest", {
  header: {
    authToken: "2ad1d6f7-e1d0-480d-86b2-dfad8af4a5b3"
  }
});

Creating a new Resource

var article = client.create("articles");
article.set("title", "foobar");
article.sync(function(err) {
  console.log("Resource created");
});

Finding Resources

client.find("articles", function(err, resources) {
  resources.map(function(resource) {
    console.log(resource.toJSON());
  });
});

Getting a specific Resource

client.get("articles", 5, { include: [ "author" ] }, function(err, article) {
  console.log(article.toJSONTree());
});

Fetching a Resource's related Resource

article.fetch("author", function(err) {
  console.log(article.author.toJSON());
});

Updating a Resource's primary relationships

article.relationships("comments").add(comment);
article.sync(function(err) {
  console.log("Resource's relation updated");
});

Deleting a Resource

article.delete(function(err) {
  console.log("Resource deleted");
});

A more complex example

}).then(function() {
  return client.create("articles")
    .set("title", "some fancy booklet")
    .set("content", "oh-la-la!")
    .relationships("tags").add(someTagResource)
    .sync();
}).then(function(newlyCreatedArticle) {