Coder Social home page Coder Social logo

enesfurkangenc / rest-to-soap-mapper Goto Github PK

View Code? Open in Web Editor NEW

This project forked from vmvini/rest-to-soap-mapper

0.0 1.0 0.0 7 KB

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

License: MIT License

JavaScript 100.00%

rest-to-soap-mapper's Introduction

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') ); 

rest-to-soap-mapper's People

Contributors

vmvini avatar drgod avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.