This project is an API that allows users to build an image repository. The app lets you view images as a non-user. Regular users can upload and delete their images. This project used Node.js, Express, PostgreSQL, and Sequelize.
To run this application:
- In your terminal type
git clone https://github.com/Ali-Aftab/ImageRepo.git
to clone it to your computer. - Then type
cd ImageRepo
to access the folder - To install the required modules type
npm i
- Make a new PostgreSQL database by writing
createdb imagerepo
- Create a .env file by typing
touch .env
to store your secret keys - In the .env file type
SECRET_JWT_KEY=ENTERYOURKEYHERE
- Type
npm run start-dev
in your terminal and you can use the API!
First, we recommend installing Postman to easily test out the API. Remember to add localhost:8000
to the URL before typing in the API path. (/api/auth/signup
=>localhost:8000/api/signup
)
Making an account is required to upload and delete your images.
- POST
/api/auth/signup
allows anyone to make an account
-Requires an email and password key inside the body
-Example {email: [email protected], password: password1} - POST
/api/auth/signin
when logged in, the response will give the user an access token. The access token must be placed in the header (with "x-access-token" as the key and the given accessToken as the value)
-Requires an email and password key inside the body. Also the x-access-token inside the header.
-The x-access-token lasts for 24 hours.
- POST
/api/image/upload
allows a registered user to upload an image
-Requires an x-access-token inside the header and the image must be attached as a file. In Postman, this can be achieved by going to the form-data option under the body section. Then change the key value from text to file.
-Can add a description to the image inside the body {description: This is image is cool} - GET
/api/image/listAll
allows anyone to view all the images data and information in the repository
-Will provide the image Id, description, and URL to the image. - GET
/api/image/:imageId
allows anyone to view one image's data and information, must provide an id.
-Replace:imageId
with the id in the URL. - GET
/api/image/direct/:imageId
allows anyone to view one image, must provide an id.
-Replace:imageId
with the id in the URL. - DELETE
api/image/imageId
allows the user to delete the image that is owned/associated with.
-Requires an x-access-token in the header and replace:imageId
with the id in the URL.