Spreddit is a Reddit clone made in Spring Boot. This API was made to my portfolio and was build with Spring Boot, Spring Data (JPA), Spring Security (JWT Authentication) and PostgreSQL.
Heroku deploy:
⚙️ API: https://spreddit-backend.herokuapp.com/swagger-ui/#/ ⚙️
The backend (this repo) is almost complete. However, I'm still building the frontend with Angular 13. These are the main features built so far:
- Register user and login/logout
- Verify account by email-sent verification token
- Use JWT tokens to make requests
- Create Subreddits
- Make posts inside the subreddits
- Comment on posts
Before starting, make sure you meet the following requirements:
- Install
Java 11
- Read the documentation in
https://spreddit-backend.herokuapp.com/swagger-ui/#/
- Transform application.properties.example to
application.properties
. - Create an account in
MailTrap
and replace the fields inapplication.properties
to you informations. - Create a database called
redditclone
in your PostgreSQL. - Replace the port of you database. If you didn't change it before, it must be
5432
. - Change the method
getApiInfo
from SwaggerConfig class to your information.
Now you can start the API.
You can access https://spreddit-backend.herokuapp.com/swagger-ui/#/ to see the documentation.
If you're running in your local machine, you can acces localhost:<your-port-usually-8080>/swagger-ui/
.
PS.: Remember to use a HttpClient to try the API (Postman, Insomnia etc).
Reading the documentation, do the following things to test Spreddit:
- Access the AuthController endpoint to register or login. Here, I'm using a free account of MailTrap for email testing, so if you try to register a new account with your email, you won't receive the confirmation token. So, you can login using username:
demouser1
and password:demouser1
. - When you log in, you will receive a Bearer token. From now on, you'll need to authenticate with your token for each request you make. In Postman, you can click on "Authorization" tab, select "Bearer Token" and paste your token.
- Pay Attention! Each token expires in 15 minutes after created. When you logged in, you received a "refreshToken". Store this data and make a POST to
/api/auth/refresh/token
with your username and the refresh token. Read the docs for details. - Now you can make all the requests listed in the docs.
- Try to create a subreddit, retrieve them, create a post, vote, comment etc. 😸
etc...