Skip to content

Instantly share code, notes, and snippets.

View mamund's full-sized avatar

Mike Amundsen mamund

View GitHub Profile
@mamund
mamund / client.js
Last active June 20, 2017 12:45
hypermedia examples
// init library and start
function init(url, title) {
g.url = url;
g.title = title||"Cj Client";
req(g.url,"get");
}
// primary loop
function parseCj() {
dump();
// Initialize WebHooks module.
var WebHooks = require('node-webhooks')
var webHooks = new WebHooks({db: './webHooksDB.json'}) // json file that store webhook URLs
// sync instantation - add a new webhook called 'shortname1'
webHooks.add('shortname1', 'http://www.webapp.com/resources/shortname1').then(function(){
// done
}).catch(function(err){console.log(err)})
// add another webHook
@mamund
mamund / api-design-example.xml
Last active August 17, 2020 21:19
API Design Example
<alps>
<doc>Simple Banking Example</doc>
<!-- actions -->
<descriptor id="getList" type="safe" />
<descriptor id="getStatus" type="safe" />
<descriptor id="updateStatus" type="idempotent">
<descriptor href="#accountId" />
<descriptor href="#actionStatus" />
</descriptor>
<descriptor id="updatePreferences" type="idempotent">
@mamund
mamund / cj-ext.js
Last active April 29, 2017 18:08
using ext link relation value
{
"collection" : {
"links" : [
{
"rel" : "ext",
"href" : "https://github.com/collection-json/extensions/blob/master/link-with-accepts.md",
"name" : "accepts-extension",
"render" : "none"
}
]
@mamund
mamund / crud-style.js
Last active April 11, 2017 05:25
jwt sample
// function passes token+context to claims store
function customerResource(request, response) {
var token = request.headers.authorization;
var body = request.body;
var method = request.method;
var url = request.url;
if(checkClaims(url, method, token.payload)===true) {
response = updateRecord("customer", body)
@mamund
mamund / huck-alps.xml
Created April 8, 2017 01:10
Huck and ALPS
<alps version="1.0">
<doc>Hypertext Command Line Interface (HCLI) semantics.</doc>
<descriptor id="hcli-document">
<descriptor href="#hcli_version" />
<descriptor href="#name" />
<descriptor id="section" type="semantic">
<descriptor href="#name" />
@mamund
mamund / page-level-properties.js
Created March 28, 2017 18:21
page-level properties for cj documentrs
{
collection: {
version: "1.0",
href: "//api.example.org/",
title: "Long List of Stuff",
properties: {
current-page: "3",
page-count: "1001",
item-count: "15034"
},
@mamund
mamund / 01-cj-suggest-inline.js
Last active March 29, 2017 14:53
cj suggest examples
{
"collection": {
"version": "1.0",
"href": "//herokuapp.com/task/",
"title": "TPS - Tasks",
"links": [...],
"items": [
{
"rel": "item",
"href": "//herokuapp.com/task/1l9fz7bhaho",
@mamund
mamund / 01-alps-search.xml
Last active February 10, 2017 20:06
stable ALPS descriptions for varying runtime messages
<alps>
<doc>ALPS search w/ varying network promises for the same named action</doc>
<!-- data -->
<descriptor id="text" type="semantic" />
<descriptor id="url" type="semantic" />
<!-- actions -->
<descriptor id="form" name="search" type="safe" rt="results">
<descriptor href="#text" name="value"/>
@mamund
mamund / alps-with-varying-rt-values.xml
Last active February 10, 2017 19:26
supporting varying returns on a single ALPS action
<alps>
<doc>varying values for @rt</doc>
<!-- data -->
<descriptor id="value" type="semantic" />
<descriptor id="title" type="semantic" />
<descriptor id="id" type="semantic" />
<descriptor id="code" type="semantic" />
<descriptor id="url" type="semantic" />
<descriptor id="waitsec" type="semantic" />