XML2Json is a RESTful API service that converts XML data into JSON format. It is designed to facilitate integration between systems that communicate using XML and those that require JSON, providing a transformation layer. The service is built with Node.js and Express, and includes validation, error handling, and logging features.
- XML to JSON Conversion: Accepts XML input and returns the equivalent JSON for valid XML data.
- Company Data API: Exposes endpoints to fetch and transform company data from XML sources.
- Health Check Endpoint: Provides a health check endpoint for monitoring.
- Validation Middleware: Ensures incoming requests are well-formed and valid.
- Error Handling: Centralized error handler for consistent API responses.
- Correlation ID Middleware: Adds correlation IDs to requests for traceability.
- Logging: Uses a Winston logger and Morgan for request logging.
- OpenAPI Spec: API is documented using OpenAPI in
openapi.yaml
. - Testing: Includes unit, e2e, and contract tests.
- Dockerized: Ready for containerized deployment with Docker and Docker Compose.
├── src/
│ ├── app.js # Express app setup
│ ├── server.js # Server entry point
│ ├── clients/ # HTTP and XML clients
│ ├── controllers/ # Route controllers
│ ├── middleware/ # Express middleware
│ ├── routes/ # API route definitions
│ ├── services/ # Business logic and XML transformation
│ ├── transformers/ # Data transformation logic
│ └── utils/ # Utility functions and logger
├── test/ # Unit, e2e, and contract tests
├── openapi.yaml # OpenAPI (Swagger) specification
├── Dockerfile # Docker image definition
├── docker-compose.yml # Docker Compose setup
├── package.json # Project metadata and scripts
└── README.md # Project documentation
GET /api/v1/health
- Returns service status.
GET /api/v1/companies/:id
- Fetches and returns a single company by ID in JSON format.
- All endpoints return consistent error responses with appropriate HTTP status codes and messages.
- Node.js (v18+ recommended)
- npm
- Docker (optional, for containerized deployment)
- Clone the repository:
git clone <repository-url> cd XML2Json - Rest API
- Install dependencies:
npm install
npm start
npm run dev
Build and run the service using Docker Compose:
docker-compose up --build
For a complete list and description of all available npm scripts, see:
For details on configuring environment variables, see:
For a complete guide on using Visual Studio Code together with Docker for development, debugging, and testing with this project, see:
- The OpenAPI specification is available in
openapi.yaml
. - You can use tools like Redoc to visualize and interact with the API.