FamSnap is a Node.js API for managing photo albums and images, including image uploads to Cloudinary. This API provides endpoints for managing albums and images using MySQL as the database and Cloudinary for image storage.
- Backend: Node.js
- Database: MySQL
- Image Storage: Cloudinary
The API exposes several endpoints for managing photo albums and images.
Base URL: https://fam-snap-node-api.vercel.app/
Auth
- POST
/auth/v1/register
: Create an account (name
,email
,password
,address
required) - POST
/auth/v1/login
Login to get access and refresh tokens (email
,password
required) - POST
/auth/v1/refresh
Refresh access token (refreshtoken
required) - DELETE
/auth/v1/logout
Logout (accesstoken
required)
Access token
will be necessary for routes with POST
, PUT
, PATCH
and DELETE
methods.
Albums
- GET
/api/v1/albums
: Retrieve all albums. - POST
/api/v1/albums
: Create a new album. (name
,description
required) - GET
/api/v1/albums/:id
: Retrieve a specific album by ID. - PUT
/api/v1/albums/:id
: Update an album by ID. - PATCH
/api/v1/albums/:id
: Partially update an album by ID. - DELETE
/api/v1/albums/:id
: Delete an album by ID.
Images
- GET
/api/v1/images
: Retrieve all images. - POST
/api/v1/images/upload
: Upload an image to Cloudinary. (form-data:image
required) - POST
/api/v1/images
: Create a new image. (title
,image
,album_id
required) - GET
/api/v1/images/:id
: Retrieve a specific image by ID. - PUT
/api/v1/images/:id
: Update an image by ID. - PATCH
/api/v1/images/:id
: Partially update an image by ID. - DELETE
/api/v1/images/:id
: Delete an image by ID.
Before you begin, ensure you have the following installed on your machine:
- Node.js (version 18.x or higher)
- npm
- MySQL
- Docker: installed on your system
- Docker Compose: installed on your system
Clone the repository on your local machine.
git clone [email protected]:KaungZayY/FamSnapNodeApi.git
cd
into cloned repository.
cd FamSnapNodeApi
Copy the .env.example
file as .env
cp .env.example .env
Setup the env variables in .env
.
npm install
git checkout DockerizedVersion
At the root of your project directory, create a new folder named public.
mkdir public
Inside the public
folder, create images
sub-folder to store images.
cd images
mkdir images
Your project directory structure should now look like this:
FamSnapNodeApi/
├── database/
├── node_modules/
├── public/
│ ├── images/
├── v1/
└── (other project files and folders)
Build the docker image by using the following bash command.
docker-compose build --no-cache
Run the Docker container in the detach mode.
docker-compose up -d
Go to http://localhost:8081/
to access phpmyadmin pannel and import the database /database/fam_snap.sql
.
docker-compose exec db mysql -u root -p
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123';
FLUSH PRIVILEGES;
Restart docker-compose
docker-compose restart
Base URL: http://localhost:3000
Auth
- POST:
/auth/v1/register
@params: name, email, password, address - POST:
/auth/v1/login
@params: email, password - POST:
/auth/v1/refresh
@params: token - DELETE:
/auth/v1/logout
@params: token
Albums
- GET :
/api/v1/albums
- POST :
/api/v1/albums
@params : name, description| @header : Bearer Token - GET :
/api/v1/albums/:id
- PUT :
/api/v1/albums/:id
@header : Bearer Token - PATCH :
/api/v1/albums/:id
@header : Bearer Token - DELETE :
/api/v1/albums/:id
@header : Bearer Token
Images
- GET :
/api/v1/images
- POST :
/api/v1/images/upload
@params : form-data:image | @header : Bearer Token - POST :
/api/v1/images
: @params : title, image, album_id | @header : Bearer Token - GET :
/api/v1/images/:id
- PUT :
/api/v1/images/:id
@header : Bearer Token - PATCH :
/api/v1/images/:id
@header : Bearer Token - DELETE :
/api/v1/images/:id
@header : Bearer Token
FamSnap API offers a robust solution for managing photo albums and image uploads, utilizing Node.js for the backend, MySQL for the database, and Cloudinary for image storage. With clear and well-structured API endpoints, users can create, retrieve, update, and delete albums and images efficiently. The Dockerized setup ensures smooth local development, and the use of environment variables allows flexibility in configuration for different environments.
Whether you are testing locally or deploying to production, this API provides a solid foundation for managing your photo albums and image assets in a scalable way.
For further improvements or contributions, feel free to fork the repository, create a feature branch, and submit a pull request. Enjoy building with FamSnap!