This project is a web platform where users can create and manage advertisements. The backend is built with Spring Boot, provides a GraphQL API, and uses JWT-based authentication for security. Users can register, log in, and manage their ads.
- User registration and login (JWT authentication)
- Add, delete, update, and list advertisements
- Flexible data querying with GraphQL API
- Simple web interface (HTML + JS) for ad creation and user actions
- Layered architecture (Controller, Service, Repository)
- Error handling and customizable exception messages
- Java 17+
- Spring Boot
- Spring Security (JWT)
- GraphQL (Spring for GraphQL)
- H2/other database support
- Basic frontend with HTML/JS
- Clone the repository:
git clone <your-repo-link> cd spring-boot-graphql-api
- Install dependencies and build the project:
./gradlew build
- Start the application:
./gradlew bootRun
- The app runs at
http://localhost:8080
by default. - GraphQL endpoint:
http://localhost:8080/graphql
- Web interfaces:
- Register:
/register
- Login:
/login
- Create advert:
/create
- Register:
- After login, your JWT token is stored in localStorage and used automatically for ad operations.
- User: id, username, email, roles
- Advert: id, title, description, price, author
query {
adverts {
id
title
description
price
author { username }
}
}
Create user:
mutation {
createUser(input: {username: "ali", email: "ali@mail.com", password: "1234"})
}
Login (returns token):
mutation {
authentication(input: {email: "ali@mail.com", password: "1234"})
}
Create advert:
mutation {
createAdvert(input: {title: "Bicycle for Sale", description: "Clean, barely used.", price: 1500}) {
id
title
}
}
- Registration and login are handled via GraphQL mutations.
- After login, the returned JWT token should be sent in the Authorization header.
- Some actions (add/delete advert) require authentication.
Contributions are welcome! Please open an issue before submitting a pull request.
This project is licensed under the MIT License. See the LICENSE file for details.
Template Used: https://github.com/Xjectro/spring-boot-graphql-api