0.1.2 • Published 8 years ago

rest-to-soap-mapper v0.1.2

Weekly downloads
3
License
MIT
Repository
github
Last release
8 years ago

rest-to-soap-mapper

Npm module that creates a bridge between existing soap web services and node-express rest apis

Installing on your node project

npm install rest-to-soap-mapper --save

Example 1 - GET method without request parameters

    var wsdl = 'http://example.com/WebService?wsdl';
    var controller = require('rest-to-soap-mapper');
    router.get('/myroute', controller(wsdl, 'desiredWebServiceMethod') ); 

In the above code, controller(wsdl, 'desiredWebServiceMethod'); is creating for me a function(req, res){} which will handle the user's get request. This handler will automatically catch error and success events in the whole process of getting the webservice client as well as its methods calls. Thus, you don't need write code to handle errors and send responses to the user.

In case of success of the desiredWebServiceMethod call, a response with the data from the webserver is automatically sent to the user.

Example 2 - GET method with request parameters

    var wsdl = 'http://example.com/WebService?wsdl';
    var controller = require('rest-to-soap-mapper');
    router.get('/myroute', controller(wsdl, 'desiredWebServiceMethod', setArgs ) );  
    
    function setArgs(req){
      return {
        param1: req.query.param1,
        param2: req.query.param2
      };
    }
    

To feed the webservice method with arguments, you need to pass a second callback function to the controller. In this case, it was the setArgs. It's worth to notice that controller passes a req object to the setArgs callback. This allows you use req object to obtain arguments from user's request and set them as arguments for the web service method.

If you want to ensure that only requests with certain parameters will be precessed, read ahead.

Example 3 - GET method with request validation

    router.get('/myroute', validation, controller(wsdl, 'desiredWebServiceMethod', setArgs ) ); 
    
    function validation(req, res, next){
      if(!req.query.param1 || !req.query.param2 ){
    		res.status(404);
    		res.json({"message":"param1 and 2 should be present"});
    		return;
    	}
    	next(); 
    }

The validation function will act as a middleware and only will pass the request to the real handler function if the request contain the desired argument.

Example 4 - POST method with request validation

    router.post('/myroute', validation, controller(wsdl, 'desiredWebServiceMethod', setArgs ) ); 
    
    function setArgs(req){
      return {
        param1: req.body.param1,
        param2: req.body.param2
      };
    }
    
    function validation(req, res, next){
      if(!req.body.param1 || !req.body.param2 ){
    		res.status(404);
    		res.json({"message":"param1 and 2 should be present"});
    		return;
    	}
    	next(); 
    }
0.1.2

8 years ago

0.1.1

8 years ago

0.1.0

8 years ago