The objective of this project is to develop a modern API based on microservices. The project is an API which you can interact to store, list, update and remove the beers you have already been tried.
We have 6 Docker containers in this project, they are:
- MySQL
- MongoDB
- MongoExpress
- Adminer
- MvnBuilder
- Api
To authenticate the API we'll use JWT Auth, we'll get the token via the login route. The users information are stored in a MySQL Docker container, and the beer information in a different MongoDB Docker container. To interact with the databases we'll have another two containers: Adminer and Mongo-Express.
There is a MvnBuilder container that uses a dependency cache so that the application does not take long to start. After that, our built application is sent to the main container that runs the API on port 5000. Because of this way of building, your local Java version isn't relevant for this project, you may not even have Java installed.
- Login to get the Token.
- Validate login/password.
- Add Kubernetes to the project.
- Get all beers.
- Get one specific beer by id.
- Add new beer.
- Update a beer by id.
- Remove a beer by id.
- Get all users.
- Get one specific user by login.
- Add new user.
- Remove user.
Before starting you need to have installed the following tools:
- Git (Optional, you may want to manually download the project)
- Docker
- Docker Compose
It is also useful to have an API Tool like Postman to interact with the API.
# Clone this repo
$ git clone https://github.com/jvictore/api-beers.git
# Enter the cloned project folder
$ cd api-beers
# That's the script you run to initialize everything, is just that simple.
$ bash run_docker.sh
The Spring REST API will initialize on port 5000. Communicate with the application by http://localhost:5000/
The API requests format can be viewed in postman after import the collection located in:
- api-beers/add-ons/api-beers.postman_collection.json
If you choose to use postman, you just have to add a new user and login using that new username/password, the login route will generate a token to authenticate (after successfully logging in, postman will automatically inherit the token to all the routes).
If you choose another method to interact with the API, you'll need the auth user/password to get a JWT Token, so let's add a new user sending a POST to the route '/user/add' with the following body:
{
"login": "SOMELOGIN",
"password": "SOMEPASSWORD"
}
Now you have to send a POST to the route '/login' with the same body of the '/user/add' route explained above. This request will return a token to authenticate, this token is of the type 'Bearer token', and will be used in all routes.
To facilitate the visualization of the databases mentinoned above, we can access:
- Mongo-Express : http://localhost:8081/
- Adminer : http://localhost:9090/
# Once you have use the application you have to terminate it
# Use the Docker Compose to do it
$ docker-compose down