resource-access.js
/**
 POST:
 Transfer content to the resource according to content media type.
 Decode the response based on the actual response Content-Type.

 @param {Object} location - the resource location
 @param {string | Object} [expression] - content to accompany the request for the resource
 @param {Object} options
 @param {string} options.Accept, - the accept media type
 @param {string} options.'Content-Type', - the content media type

 see: https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types
 */
Transfer content to the resource according to content media type.
Decode the response based on the actual response Content-Type.
Transfer content to the resource according to content media type . Decode the response based on the actual response Content - Type .
function postResource (location, content, options, continuation, fail) {
  log.debug("postResource: ", location, content, options);
  function invokeImplementation(implementation) {
    if (continuation) {
      log.debug("postResource: with continuation");
      return (implementation(location, content, options, continuation, fail || log.warn));
    } else {
      log.debug("postResource: as promise");
      return (new Promise(function(accept, reject) {
               log.debug("postResource: promise invoked: ", accept, reject);
               implementation(location, content, options, accept, reject || fail || log.warn) })
             );
    }
  }
  var acceptType = options['Accept'];
  if (! acceptType) {
    console.trace();
    throw (new Error("postResource: Accept option is required."));
  }
  var acceptMatch = mediaTypeStem(acceptType);
  if (acceptMatch) {
    let implementation = postResource[acceptMatch];
    switch(typeof(implementation)) {
    case "function":
      return (invokeImplementation(implementation));
    case "object":
      var contentType = options['Content-Type'];
      var contentMatch = (contentType ? mediaTypeStem(contentType) : "*");
      if (contentMatch) {
        implementation = implementation[contentMatch] || implementation["*"];
        switch(typeof(implementation)) {
        case "function":
          return (invokeImplementation(implementation));
        default:
          console.trace();
          throw (new Error(`postResource: unimplemented media type combination: '${acceptType}'.'${contentType}'`));
        }
      } else {
        console.trace();
        throw (new Error(`postResource: unrecognized media type: '${contentType}'`));
      }
    default:
      console.trace();
      throw (new Error(`postResource: unrecognized media type implementation: '${acceptType}': ${implementation}`));
    }
  } else {
    console.trace();
    throw (new Error(`postResource: unrecognized media type: '${acceptType}'`));
  }
}
function postResource ( location , content , options , continuation , fail ) { log . debug ( "postResource: " , location , content , options ) ; function invokeImplementation ( implementation ) { if ( continuation ) { log . debug ( "postResource: with continuation" ) ; return ( implementation ( location , content , options , continuation , fail || log . warn ) ) ; } else { log . debug ( "postResource: as promise" ) ; return ( new Promise ( function ( accept , reject ) { log . debug ( "postResource: promise invoked: " , accept , reject ) ; implementation ( location , content , options , accept , reject || fail || log . warn ) } ) ) ; } } var acceptType = options [ 'Accept' ] ; if ( ! acceptType ) { console . trace ( ) ; throw ( new Error ( "postResource: Accept option is required." ) ) ; } var acceptMatch = mediaTypeStem ( acceptType ) ; if ( acceptMatch ) { let implementation = postResource [ acceptMatch ] ; switch ( typeof ( implementation ) ) { case "function" : return ( invokeImplementation ( implementation ) ) ; case "object" : var contentType = options [ 'Content-Type' ] ; var contentMatch = ( contentType ? mediaTypeStem ( contentType ) : "*" ) ; if ( contentMatch ) { implementation = implementation [ contentMatch ] || implementation [ "*" ] ; switch ( typeof ( implementation ) ) { case "function" : return ( invokeImplementation ( implementation ) ) ; default : console . trace ( ) ; throw ( new Error ( ` ${ acceptType } ${ contentType } ` ) ) ; } } else { console . trace ( ) ; throw ( new Error ( ` ${ contentType } ` ) ) ; } default : console . trace ( ) ; throw ( new Error ( ` ${ acceptType } ${ implementation } ` ) ) ; } } else { console . trace ( ) ; throw ( new Error ( ` ${ acceptType } ` ) ) ; } }
POST:
Transfer content to the resource according to content media type.
POST : Transfer content to the resource according to content media type .
// invoke the implementation. specify the static class context and pass the given arguments