This project is a RESTful API built using TypeScript, MongoDB, Node.js, and Express. The API allows users to upload, retrieve, and delete images stored in a MongoDB database. Images are stored in base64 format, and the API supports image formats such as JPG, PNG, and GIF.
- Upload images in JPG, PNG, and GIF formats.
- Retrieve a list of stored images.
- Retrieve a specific image by ID.
- Delete an image by ID.
You can interact with the API in two ways by either cloning the repo or using the deployed URL
The API is deployed on Render at https://mongo-image-api.onrender.com. You can interact with the API using Postman or any HTTP client.
Ensure that you have the following installed:
- Node.js
- MongoDB
- npm
-
Clone the repository:
git clone https://github.com/khairatAA/mongo-image-api.git
-
Navigate to the project directory:
cd mongo-image-api
-
Install dependencies:
npm install
Create a .env file in the project root and configure the following variables:
PORT=3000
MONGODB_URI=mongodb://your-mongodb-uri/image_api
Description: Uploads an image to the database.
Usage:
- Open Postman.
- Set the request type to POST.
- Enter the API endpoint URL: https://mongo-image-api.onrender.com/upload.
- Set the request body to form-data.
- Add a key named image and select a file for the value.
- Send the request.
Description: Retrieves a list of all stored images.
Usage:
- Open Postman.
- Set the request type to GET.
- Enter the API endpoint URL: https://mongo-image-api.onrender.com/get_images.
- Send the request.
Description: Retrieves a specific image by ID.
Usage:
- Open Postman.
- Set the request type to GET.
- Enter the API endpoint URL: https://mongo-image-api.onrender.com/get_image/{image_id}.
- Replace
{image_id}
with the actual ID of the image you want to retrieve. - Send the request.
- Save response to a file and add an extension (the value in its content file) e.g .png, .jpeg or .gif
Description: Deletes an image by ID.
Usage:
- Open Postman.
- Set the request type to DELETE.
- Enter the API endpoint URL: https://mongo-image-api.onrender.com/delete_image/{image_id}.
- Replace
{image_id}
with the actual ID of the image you want to delete. - Send the request.