X-Road Client Library for Nodejs
X-Road Client provides a Nodejs library for building X-Road v6 Adapter clients. The library takes care of serialization and deserialization of SOAP and REST messages offering built-in support for standard X-Road SOAP and REST headers; only processing of application specific request and response content remains to be implemented
Installation
npm install --save xroad-client
Usage
- Create the consumer instance
; // Create the configuration object pointing to // the consumer security serverconst xRoadConfig = securityServer: "127.0.0.1" // The security server address client: xRoadInstance: 'BR' // The x-road instance memberClass: 'GOV' // The consumer member class memberCode: '123456' // The consumer member code subsystemCode: '98765' // The consumer subsystem code // create the consumer instanceconst consumer = xRoadConfig;
- Consuming a REST service
// Create the request objectconst requestConfig = method: "POST" // The request method secure: false // If true uses https instead of http service: xRoadInstance: 'BR' // The x-road instance memberClass: 'GOV' // The provider member class memberCode: '45678' // The provider member code subsystemCode: '8765' // The provider subsystem code serviceCode: `myVehicles` // The service to be consumed headers: // Custom headers can be passed here body: JSON; // Consuming a rest Serviceconst restClient = consumer;const response = restClient; console;
- Consuming a SOAP service
// Create the request objectconst requestConfig = secure: false // If true uses https instead of http service: xRoadInstance: 'BR' // The x-road instance memberClass: 'GOV' // The provider member class memberCode: '45678' // The provider member code subsystemCode: '8765' // The provider subsystem code serviceCode: `myVehicles` // The service to be consumed headers: // Custom headers can be passed here body: `<con:myVehiclesBody xmlns:con="https://www.sr.gov.br/services/cons"> <id>456789</id> </con:myVehiclesBody>` ; const restClient = consumer;const response = restClient; console;