Skip to content

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

License

Notifications You must be signed in to change notification settings

vmvini/rest-to-soap-mapper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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(); 
    }

Example 5 - GET method with HTTP Basic Authentication

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

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published