1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
// Copyright 2019 Campbell Crowley. All rights reserved.
// Author: Campbell Crowley (dev@campbellcrowley.com)
/**
* @classdesc Data associated with describing an API endpoint, and instructions
* on where to send data as well as what data is allowed.
* @class
*/
class ApiEndpoint {
/**
* @description Create an instance.
* @param {string} name The name of this endpoint.
* @param {string} host The hostname to direct data to for this request.
* @param {string} path The url path to direct data for this request.
* @param {object} [options] Additional options for controlling request data.
* @param {string[]} [options.accept=[]] Acceptable content-type headers.
* @param {number} [options.maxLen=0] Maximum number of bytes allowed per
* request.
* @param {string[]} [options.methods=['GET,'POST']] Acceptable http methods
* for requests.
*/
constructor(name, host, path, options = {}) {
if (!options) options = {};
/**
* @description The name of the API endpoint.
* @public
* @type {string}
*/
this.name = name;
/**
* @description The hostname of the url to redirect data.
* @public
* @type {string}
*/
this.host = host;
/**
* @description The url path to redirect data.
* @public
* @type {string}
*/
this.path = `/socket.io/${path}`;
/**
* @description List of acceptable content-type headers.
* @public
* @type {string[]}
* @default ['application/json']
*/
this.accept = options.accept || ['application/json'];
/**
* @description Maximum number of bytes allowed per request.
* @public
* @type {number}
* @default 0
*/
this.maxLen = options.maxLen || 0;
/**
* @description List of acceptable request methods.
* @public
* @type {string[]}
* @default ['GET', 'POST']
*/
this.methods = options.methods || ['GET', 'POST'];
}
}
module.exports = ApiEndpoint;