Basic middleware REST API made in Spring that fetches online product data and creates endpoints from which we can:
- search all products (product attributes are: name, price, short description and image)
- search specific products (specified by the product's id)
- search all categories
- search products by keywords
- filter products by price and/or category
You have to install Docker and Docker Compose.
Everything else will be installed automatically by following the steps in the Installation section.
With GitHub account:
git clone https://github.com/PjotrVr/king-spring-service
cd king-spring-service
Or with SSH:
git clone [email protected]:PjotrVr/king-spring-service.git
cd king-spring-service
docker-compose up --build -d
docker-compose down
Since this is just a REST API and not an actual app, I'd recommend using tools like Postman or Insomnia for easier usage.
If you don't have any of such tools, you can still make requests by using your browser and devtools extension.
Available endpoints:
- GET /products: fetches all products
- GET /products/categories: fetches all products and makes a list of distinct categories
- GET /products/{id}: fetches specific product by its id if it exists
- GET /products/filter?{filter}: fetches all products and then filters them by category and price range
- GET /products/search?{query}: fetches all products and returns sorted list based on query-to-product matching algorithm
For more detailed explanation of endpoints, read API documentation.
Everything that is configurable is inside .env file.
Parameters that you can change:
- PORT: port that server will run on, DEFAULT: 8080
- DB_NAME: database name, DEFAULT: springdb
- DB_USERNAME: database username, DEFAULT: admin
- DB_PASSWORD: database password, DEFAULT: admin
- LOG_FILE: name of logging file, DEFAULT: application.log
By default, you can access database through h2 console.
Start the application.
Go to /h2-console
and login with .env information. Don't forget to set path to database.
Basic:
- Implement
/products
endpoint - Implement
/products/categories
endpoint - Implement
/products/{id}
endpoint - Implement
/products/filter
endpoint - Implement
/products/search
endpoint
Nice to have:
- Add tests for all endpoints
- Add basic authentication and authorization
- Add logging
- Add caching for similar product retrieval
- Add docker