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

json-schema-agent-component

v0.0.16

Published

JSON Hyper-Schema HTTP client

Downloads

4

Readme

json-schema-agent

Please note this library is not ready for production use.

JSON Hyper-Schema HTTP REST client. Together with json-schema-core and json-schema-hyper, this library provides a basic mechanism for correlating instances with schema over HTTP. It also provides validation of request and response messages (schema and targetSchema), if json-schema-valid is used.

Refer to the JSON Schema Core v4 and Hyper-Schema IETF Internet Draft specs for more info.

Installation

component:

$ component install ericgj/json-schema-agent

npm:

$ npm install json-schema-agent-component

Examples


// Simple GET

var agent = new Agent();
agent.get('http://some.uri/path', function(err,correlation){
  correlation.instance  // the JSON instance (parsed body of response)
  correlation.schema    // the schema
})


// POST using link attributes

var link = { href: 'http://example.com/thing',
             rel: 'create',
             mediaType: 'application/vnd.thing+json'
           }

agent.post(link, obj, fn);

// or automatically follow method defined in link

link.method = 'POST'
agent.follow(link, obj, fn);


// follow chain of links

agent.follow(link, function(err, correlation){
  var nextItem = correlation.rel('next');  // find link rel="next" in the schema
  agent.follow(nextItem, fn)
})


// fetch and dereference schema from link
// note schema is cached to the agent

agent.getSchema(link, function(err,schema){
  schema    // the parsed, dereferenced schema
})


// dereference raw schema object

agent.dereference(data, function(err,schema){
  schema    // the parsed, dereferenced schema
})


// Configuration

// set default base uri for resolving relative URIs in links
// in-browser, typically you'd want to set this to window.location.origin

agent.base('http://example.com/api'); 


// set underlying http client (class)
var httpClient = require('superagent');
Agent.service(httpClient);

API

Running tests

In browser:

  1. Unit tests:
  • browse to file:// test/index.html
  • browse to file:// test/refs.html
  1. Functional tests:
$ node test/server.js

And browse to http://localhost:3000/functional.html

In Node-land:

  1. Unit tests:
$ npm test
  1. Functional tests:
$ node test/server.js &
$ mocha --ui bdd test/functional.js

License

MIT

Limitations

  • Note that an underlying HTTP client library must be specified, it is not built-in. The API for requests/responses is equivalent to a simple subset of superagent's. So superagent is the easiest choice, but not the only one.

  • The Correlation object is implemented in json-schema-core, and extended in json-schema-hyper, qq.v. for more examples of usage.

  • Both Content-Type and Link header -style correlation methods are supported (see Core, sec. 8). However, specification of the root relation via the Link header (see Hyper-Schema, sec. 4.2), is not currently supported. This may be implemented in the future.

  • This library provides parsing of the media property within schemas, however the internal representation of media type values (i.e., the use of this information in parsing the values) is left for the upstream application.

  • The readOnly property within Link Description Object (LDO) schemas is not currently validated during write operations (POST/PUT/PATCH). It is not clear from the spec whether it is the responsibility of the client to do so.

  • The pathStart schema property is not currently validated when correlating instances (Hyper-Schema, sec. 4.5). This may be implemented in the future.

  • Likewise, the determination of authoritative representation of the self link target is not currently implemented (Hyper-Schema, sec. 5.2.2), but may be in the future.