Skip to content

icaroNZ/XML2Json---Rest-API

Repository files navigation

XML2Json - Rest API

Overview

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.

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.

Project Structure

├── 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

API Endpoints

Health Check

  • GET /api/v1/health
    • Returns service status.

Company Data

  • GET /api/v1/companies/:id
    • Fetches and returns a single company by ID in JSON format.

Error Handling

  • All endpoints return consistent error responses with appropriate HTTP status codes and messages.

Usage

Prerequisites

  • Node.js (v18+ recommended)
  • npm
  • Docker (optional, for containerized deployment)

Installation

  1. Clone the repository:
    git clone <repository-url>
    cd XML2Json - Rest API
  2. Install dependencies:
    npm install

Running the Application

Locally

npm start

In Development Mode (with auto-reload)

npm run dev

With Docker

Build and run the service using Docker Compose:

docker-compose up --build

Project npm Scripts

For a complete list and description of all available npm scripts, see:

Configuration

For details on configuring environment variables, see:

Developing with VS Code and Docker

For a complete guide on using Visual Studio Code together with Docker for development, debugging, and testing with this project, see:

API Documentation

  • The OpenAPI specification is available in openapi.yaml.
  • You can use tools like Redoc to visualize and interact with the API.

About

XML to Json converter

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published