Skip to content

Latest commit

 

History

History
76 lines (52 loc) · 4.19 KB

README.md

File metadata and controls

76 lines (52 loc) · 4.19 KB

Spreddit - Backend

Java Spring Postgres Swagger Heroku Reddit

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/#/ ⚙️

Adjustments and Improvements

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

💻 Requirements

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 in application.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.

☕ Testing Spreddit

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:

  1. 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.
  2. 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.
  3. 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.
  4. Now you can make all the requests listed in the docs.
  5. Try to create a subreddit, retrieve them, create a post, vote, comment etc. 😸

📸 Screenshots

Login

Screenshot from 2022-02-02 16-22-33

Get all subreddits

Screenshot from 2022-02-02 16-27-54

Create new subreddit

Screenshot from 2022-02-02 16-31-50

Create new post inside a subreddit

Screenshot from 2022-02-02 16-37-02

Find posts inside a subreddit

Screenshot from 2022-02-02 16-38-05

etc...