UNPKG

haleoas

Version:
175 lines 6.58 kB
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width" charset="utf-8"> <title>haleoas</title> <link rel="stylesheet" href="css/bootstrap.min.css"> <link rel="stylesheet" href="css/cayman.min.css"> <link rel="stylesheet" href="css/prism.min.css"> <link rel="stylesheet" href="css/index.min.css"> <link rel="stylesheet" href="css/docs.min.css"> <link rel="stylesheet" href="css/bootstrap-responsive.min.css"> </head> <body data-spy="scroll" data-target=".scrollspy"> <div class="navbar navbar-inverse navbar-fixed-top"> <div class="navbar-inner"> <div class="container"><a class="brand">Mr. Doc</a> <div class="nav-collapse collapse"> <ul class="nav pull-right sponsored"></ul> </div> </div> </div> </div> <header id="overview" class="jumbotron subhead"> <div class="container"> <h1>haleoas</h1> <p class="lead"></p> </div> </header> <div class="container"> <div class="row"> <div class="span3 bs-docs-sidebar"> <ul class="nav nav-list bs-docs-sidenav affix-top"> <li class="active"><a href="index.html">Main</a></li> <li><a href="haleoas.js.html">haleoas.js</a></li> </ul> <div class="scrollspy"> <ul class="nav nav-list bs-docs-sidenav affix-top"> </ul> </div> </div> <div class="span9"> <section id="Main" class="readme"><h1>HALEOAS</h1> <h2>HAL Hypermedia REST Client</h2> <p>Supported HTTP Methods:</p> <ul> <li><code>GET</code> : supports url templating params using <a href="http://tools.ietf.org/html/rfc6570">RFC6570</a></li> <li><code>HEAD</code></li> <li><code>OPTIONS</code></li> <li><code>PUT</code> : sends everything except <code>_link</code> as <code>content-type: application/json</code></li> <li><code>POST</code></li> <li><code>PATCH</code> : conforms to <a href="http://tools.ietf.org/html/rfc6902">RFC6902</a> and sends <code>content-type:application/json-patch+json</code></li> <li><code>DELETE</code></li> </ul> <h3>Browser support</h3> <p>When running browser tests, a modern web server is expected ^1.1.</p> <ul> <li>Safari borks by babel-core because of <a href="https://github.com/thlorenz/convert-source-map/issues/31">this silliness</a></li> </ul> <h3>Size</h3> <ul> <li><strong>unminified</strong> ~3.8kb</li> <li><strong>minified</strong> ~1.4kb</li> </ul> <h3>Running tests</h3> <p><strong>NodeJS</strong> <code>npm test</code></p> <p><strong>Browser</strong></p> <p><code>npm serve</code></p> <p>In your browser, visit <code>http://localhost:3000/test-runner.html</code> and look in the console.</p> <h3>Usage</h3> <p><strong>BREAKING CHANGE AS OF v0.3.0: All HTTP methods may receive a full request config object + <code>data</code> and <code>params</code></strong></p> <p>A full Request object may be passed into all methods. For mutating methods, a <code>data</code> JSON parameter may be passed for serializing to the request body. For all methods a <code>params</code> Object parameter may be passed for expanding templated urls.</p> <h4>GET</h4> <pre><code class="language-js">import haleoas from ‘haleoas’ let hal = haleoas({ fetch: myFetchImpl }) let resource = hal({ self: ‘http://my.api.com{?foo’}) /** * GET /?foo=bar HTTP/1.1 * Host: http://my.api.com * Accept: application/hal+json **/ resource.get({ params: { foo: ‘bar’, } }).then({ resource, response }) =&gt; { //the resource, mapped to the HAL body and ready for traversal //the response, whatever is returned from `fetch` }) </code></pre> <h4>POST</h4> <pre><code class="language-js">import haleoas from ‘haleoas’ let hal = haleoas({ fetch: myFetchImpl }) let resource = hal({ self: ‘http://my.api.com’}) /** * POST / HTTP/1.1 * Host: http://my.api.com * Content-Type: application/json * Accept: application/hal+json * * { * “foo”: “bar” * } **/ resource.post({ data: { foo: ‘bar’, }, params: { q: 'foo' } }).then({ resource, response }) =&gt; { //the resource, mapped to the HAL body and ready for traversal // or, if a 201 with a `location` is returned, the new entity is returned //the response, whatever is returned from `fetch` }) </code></pre> <h4>DELETE</h4> <pre><code class="language-js">import haleoas from ‘haleoas’ let hal = haleoas({ fetch: myFetchImpl }) let resource = hal({ self: ‘http://my.api.com’}) /** * DELETE / HTTP/1.1 * Host: http://my.api.com * Accept: application/hal+json **/ resource.delete().then({ resource, response }) =&gt; { //the resource, mapped to the HAL body and ready for traversal //the response, whatever is returned from `fetch` }) </code></pre> <h4>PATCH</h4> <pre><code class="language-js">import haleoas from ‘haleoas’ let hal = haleoas({ fetch: myFetchImpl }) let resource = hal({ self: ‘http://my.api.com’}) /** * PATCH / HTTP/1.1 * Host: http://my.api.com * Accept: application/hal+json * Content-Type: application/json-patch+json * * [ * { * “op”:“add”, * “path”: “/foo”, * “value”: “bar” * } *] **/ resource.patch({foo:bar}).then({ resource, response }) =&gt; { //the resource, mapped to the HAL body and ready for traversal //the response, whatever is returned from `fetch` }) </code></pre> </section> </div> </div> </div> <footer class="footer"> <div class="container"> <p>Documentation generated with <a href="https://github.com/mr-doc/mr-doc">Mr. Doc </a> created by <a href="https://twitter.com/FGRibreau" data-show-count="false" class="twitter-follow-button">Francois-Guillaume Ribreau </a></p> <p>Mr. Doc is sponsored by <a href="http://bringr.net/?btt" title="Outil d'analyse des réseaux sociaux" class="bringr">Bringr </a> and <a href="https://redsmin.com/?btt" title="Full Redis GUI" class="redsmin">Redsmin</a></p> <p>Theme borrowed from Twitter Bootstrap</p> </div> </footer> <script src="js/twitter-widget.min.js"></script> <script src="js/jquery.min.js"></script> <script src="js/bootstrap-transition.min.js"></script> <script src="js/bootstrap-scrollspy.min.js"></script> <script src="js/bootstrap-dropdown.min.js"></script> <script src="js/bootstrap-collapse.min.js"></script> <script src="js/bootstrap-affix.min.js"></script> <script src="js/prism.min.js"></script> <script src="js/index.min.js"></script> </body> </html>