Skip to content

Spring REST API based on microservices using Docker containers. We use MongoDB to save the authorized users and MySQL to save the data.

Notifications You must be signed in to change notification settings

jvictore/api-beers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

API Beers

Spring REST API to register all beers that have already been tried.

ObjectiveDescriptionFeaturesPre-RequisitesHow to runHow to terminateAccess the Databases

🚧 Project in development... 🚧

Objective:

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.

Description:

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.

Features:.

Tools:

  • Login to get the Token.
  • Validate login/password.
  • Add Kubernetes to the project.

Beers:

  • Get all beers.
  • Get one specific beer by id.
  • Add new beer.
  • Update a beer by id.
  • Remove a beer by id.

Users:

  • Get all users.
  • Get one specific user by login.
  • Add new user.
  • Remove user.

Pre-requisites:

Before starting you need to have installed the following tools:

It is also useful to have an API Tool like Postman to interact with the API.

How-to-run

# 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.

Access-the-databases

To facilitate the visualization of the databases mentinoned above, we can access:

How-to-terminate

# Once you have use the application you have to terminate it
# Use the Docker Compose to do it
$ docker-compose down

About

Spring REST API based on microservices using Docker containers. We use MongoDB to save the authorized users and MySQL to save the data.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published