Code Monkey home page Code Monkey logo

nanoservices's Introduction

nanoservices

  • Simple framework to develop modular apex services
  • Supports extensible service factory to add custom service factory
  • All default methods can be overriden to add custom functionality
  • Interoperable with System.Callable

Sample Usage

Extend AbstractNanoService

public class CalculatorNanoService extends AbstractNanoService {
	
    public override Object execute(Map<String,Object> params) {
        
        NanoService addService = service('AdditionService')
            .thenExecute( params )
            .pass( 'AdditionServicePassService' )
            .fail( 'AdditionServiceFailService' );

        Object resultValue = addService.result();

        if(  resultValue == null ){
        	System.debug( 'Errors In The Service '+addService.errors());
        }

        return resultValue;
    }
}

public class AdditionService extends AbstractNanoService {
    public override Object execute(Map<String,Object> params) {
        Integer no1,no2;
        try {
            no1 = Integer.valueOf(params.get('no1'));
            no2 = Integer.valueOf(params.get('no2'));

            output('result',no1+no2);
            
            return no1+no2;

        } catch (Exception exp){
            error('AdditionServiceException',exp);
        }
        
        return null;
    }
}

public class AdditionServicePassService extends AbstractNanoService {

	public override Object execute(Map<String,Object> params) {

        Integer result = Integer.valueOf( pipe() );
        System.debug('pipe result ='+result);

        Integer outputResult = Integer.valueOf(params.get('result'));
		System.debug(' outputResult ='+outputResult);

        return result;
    }
}


public class AdditionServiceFailService extends AbstractNanoService {
	public override Object execute(Map<String,Object> errors) {
        //errors
        for( String errorKey : errors.keySet() ) {
        	System.debug(errorKey +' : '+ ((Exception)errors.get(errorKey)) );
        	error(errorKey,errors.get(errorKey));
        }

        return null;
    }
}



Invoke as a normal class or from another NanoService

Normal Class :

NanoService instance = new CalculatorNanoService();
instance.execute(new Map<String,Object>{
    'no1' => 1,
    'no2' => 50
});

Another NanoService :

service('CalculatorNanoService')
      .execute(new Map<String,Object>{
	    'no1' => 1,
	    'no2' => null
      });

nanoservices's People

Contributors

swapnilshrikhande 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.