This is a simple RESTful API for working on Crypto Data from CoinGecko using Node.js, Mongoose and MongoDB.
-
Clone the repository:
git clone https://github.com/yourusername/coin_convert.git
-
Navigate to the project directory
cd coin_convert
- Install dependencies:
npm install
- Configure MongoDB connection:
- Create a .env file in the root directory.
- Add your MongoDB connection string: MONGODB_URI=your_mongodb_connection_string
- Also add the API URLs to get the data from CoinGecko. Ref : https://www.coingecko.com/api/documentation
-
Run the code in Dev Mode:
npm run dev
-
Run The Command:
npm start
- Endpoint:
GET /
- Description: Testing Route .
- Example Request Body: Not Required
- Example Response:
{ "message": "Working" }
- Endpoint:
POST api/v1/coins/update
- Description: Add/Update the data in Database.
- Example Request Body: Not Required
- Example Response:
{ "success":true, "message":"Database Updated" }
-
Endpoint:
POST /api/v1/coin/convert
-
Description: Converts the value of One Coin in terms of other based on there rates on specific date.
-
Example Request Body:
{ "fromCurrency": "bitcoin", "toCurrency": "0x", "date": "12-2-2023" }
-
Example Response:
{ "success": true, "data": "1 Bitcoin = 90074.57414353701 0x Protocol" }
Appropriate Error handlers are in place to return meaningful error message with appropriate statusCode.
A Cron Job is also defined in the server that updates the Database every hour.