JSON Hyper-Schema HTTP client
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 (
json-schema-valid is used.
$ component install ericgj/json-schema-agent
$ npm install json-schema-agent-component
// Simple GETvar agent = ;agent// POST using link attributesvar link = href: ''rel: 'create'mediaType: 'application/vnd.thing+json'agent;// or automatically follow method defined in linklinkmethod = 'POST'agent;// follow chain of linksagent// fetch and dereference schema from link// note schema is cached to the agentagent// dereference raw schema objectagent// Configuration// set default base uri for resolving relative URIs in links// in-browser, typically you'd want to set this to window.location.originagent;// set underlying http client (class)var httpClient = ;Agent;
$ node test/server.js
And browse to
$ npm test
$ node test/server.js &$ mocha --ui bdd test/functional.js
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.
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.
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.
pathStart schema property is not currently validated when correlating
instances (Hyper-Schema, sec. 4.5). This may be implemented in
Likewise, the determination of authoritative representation of the
link target is not currently implemented
(Hyper-Schema, sec. 5.2.2), but may be in the future.