Skip to content

Commit

Permalink
feat(routing): create rest api endpoints, get, post, put, delete, hea…
Browse files Browse the repository at this point in the history
…d, options, and universal route
  • Loading branch information
teclone committed Jul 20, 2018
1 parent 3eabdb1 commit f8aaa7f
Showing 1 changed file with 85 additions and 0 deletions.
85 changes: 85 additions & 0 deletions src/modules/Router.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,89 @@ export default class Router {
get [Symbol.toStringTag]() {
return 'Router';
}

/**
* processes the route
*@param {string} routeUrl - the route's url
*@param {Function} callback - callback function
*@param {Object} [options] - optional configuration options
*@param {Array} [options.methods] - array of methods allowed
*@param {string} [overrideMethod] - a string indicating the only method allowed for the route
*@returns {boolean}
*/
process(routeUrl, callback, options, overrideMethod) {
if (this.resolved)
return;
}

/**
* performs route rules for all http method verbs
*@param {string} routeUrl - the route url
*@param {Function} - callback function
*@param {Object} [options] - optional configuration options
*@param {Array} [options.methods] - array of methods allowed
*/
route(routeUrl, callback, options) {
this.process(routeUrl, callback, options, '');
}

/**
* performs route rules for only GET request method verb
*@param {string} routeUrl - the route url
*@param {Function} - callback function
*@param {Object} [options] - optional configuration options
*/
get(routeUrl, callback, options) {
this.process(routeUrl, callback, options, 'GET');
}

/**
* performs route rules for only HEAD request method verb
*@param {string} routeUrl - the route url
*@param {Function} - callback function
*@param {Object} [options] - optional configuration options
*/
head(routeUrl, callback, options) {
this.process(routeUrl, callback, options, 'HEAD');
}

/**
* performs route rules for only OPTIONS request method verb
*@param {string} routeUrl - the route url
*@param {Function} - callback function
*@param {Object} [options] - optional configuration options
*/
options(routeUrl, callback, options) {
this.process(routeUrl, callback, options, 'OPTIONS');
}

/**
* performs route rules for only DELETE method verb
*@param {string} routeUrl - the route url
*@param {Function} - callback function
*@param {Object} [options] - optional configuration options
*/
delete(routeUrl, callback, options) {
this.process(routeUrl, callback, options, 'DELETE');
}

/**
* performs route rules for only POST request method verb
*@param {string} routeUrl - the route url
*@param {Function} - callback function
*@param {Object} [options] - optional configuration options
*/
post(routeUrl, callback, options) {
this.process(routeUrl, callback, options, 'POST');
}

/**
* performs route rules for only PUT request method verb
*@param {string} routeUrl - the route url
*@param {Function} - callback function
*@param {Object} [options] - optional configuration options
*/
put(routeUrl, callback, options) {
this.process(routeUrl, callback, options, 'PUT');
}
}

0 comments on commit f8aaa7f

Please sign in to comment.