Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Currency Conversion Microservice

Communication Contract

Starting the server

Making Requests

ZMQ Mode

The ZMQ server (appZMQ.js) listens for client requests on port 5555 using the REQ-REP pattern of ZeroMQ.

Steps:

  1. Client sends a JSON-encoded string to the server containing the amount, source currency, and target currency.
  2. Server responds with the conversion result or an error message.

Example Request (ZMQ):

{
  "amount": 100,
  "from_currency": "USD",
  "to_currency": "EUR"
}

Response:

{
  "type": "currency_convert_response",
  "from_currency": "USD",
  "to_currency": "EUR",
  "original_amount": 100,
  "converted_amount": 90.5,
  "rate": 0.905,
  "timestamp": 1698287200000
}

HTTP Mode

The HTTP server runs using app.js and listens for POST requests on /convert. Clients can send a JSON request with the following fields:

  • amount: The amount to be converted.
  • from_currency: The currency to convert from.
  • to_currency: The target currency.

Example Request (HTTP):

{
  "amount": 100,
  "from_currency": "USD",
  "to_currency": "EUR"
}

Response:

{
  "type": "currency_convert_response",
  "from_currency": "USD",
  "to_currency": "EUR",
  "original_amount": 100,
  "converted_amount": 90.5,
  "rate": 0.905,
  "timestamp": 1698287200000
}

Run the HTTP server:

node app.js

Receiving Data

The service returns a JSON response with the following fields:

  • type: Always "currency_convert_response"
  • from_currency: Original currency code
  • to_currency: Target currency code
  • original_amount: Input amount
  • converted_amount: Converted amount in target currency
  • rate: Exchange rate used
  • timestamp: Unix timestamp of conversion

Example successful response:

{
  "type": "currency_convert_response",
  "from_currency": "USD",
  "to_currency": "EUR",
  "original_amount": 100,
  "converted_amount": 91.85,
  "rate": 0.9185,
  "timestamp": 1700432991657
}

Error responses will have a 400 or 500 status code, and will return:

{
  "error": "Error message",
  "details": "Additional error details" // only on 500 errors
}
sequenceDiagram
  participant A as Client
  participant B as Currency Converter
  participant C as External API
  
  A->>B: Send JSON via POST
  opt If invalid Amount
  B->>A: Return Error
  end
  
  B->>B: Build JSON request
  B->>C: Get Exchange Rate

  opt If invalid Currency code
  C->>B: Return Error
  B->>A: Return Error
  end

  B->>B: Build JSON Response

  B->>A: Return JSON with currency
Loading

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages