0.0.5 • Published 7 years ago

validated-request v0.0.5

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

validated-request

Prevent your system from sending request with incorect parameters

use case

  • Sending log data to a logging server that provides analysis tools on the log
var ValidatedRequest = require('validated-request');
// protocol says that we can only make GET requests
var validatedRequest = new ValidatedRequest([{ method: 'GET', headers: { 'Content-Type': 'string' } }]);

var url = '<host>/api',
    headers = { 'Content-Type': 'application/json' },
    body = {
        request: 'what can you do',
        response: 'I can tell you a joke!'
    };

validatedRequest.get(url, headers) // this will work!
validatedRequest.post(url, headers, body) // this will NOT work because aggrement is that the system should only make GET requests

api

  • Sending get request
var ValidatedRequest = require('validated-request');
// protocol says that we can only make GET requests
var validatedRequest = new ValidatedRequest([{
     method: 'GET',
     query: { 'userId': 'string', limit: 'number' },
     headers: { 'Content-Type': 'string' }
}]);

var url = '<host>/api?userId=mars&limit=10',
    headers = { 'Content-Type': 'application/json' };

validatedRequest.post(url, headers) 
// @return Promise.resolve<{ response, body }>
// @return Promise.reject<{ response, error }>
  • Sending post request
var ValidatedRequest = require('validated-request');
// protocol says that we can only make POST requests
var validatedRequest = new ValidatedRequest([{
     method: 'POST',
     headers: { 'Content-Type': 'string' },
     body: { request: 'string', response: 'string' }
}]);

var url = '<host>/api',
    headers = { 'Content-Type': 'application/json' },
    body = {
        request: 'what can you do',
        response: 'I can tell you a joke!'
    };

validatedRequest.post(url, headers, body)
// @return Promise.resolve<{ response, body }>
// @return Promise.reject<{ response, error }>
0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago