BeAPI Framework Installation

Getting started with the BeAPI Springboot Starter is a simple process. Prior to building and running though, we must first talk installation.


Requirements

  • The BeAPI™ API Framework has the following project requirements:


  • Start by cloning the demo project to a local directory:

    git clone https://github.com/Beapi-io/beapi-java-demo.git

Configure Demo Project

You will also need to configure your project by changing your...



Setup Demo Project DB

You will now need to setup your database and edit your beapi_db.yml file (please DB section under 'Configure Demo Project'). This will allow you to setup your default DB for the demo project.

  • Login to MySQL via the shell from the directory in which the 'boot.sql' file is and use the following commands:
    mysql -uroot -p{yourpassword}
    create database boot;
    use boot;
    source boot.sql;
    GRANT ALL ON boot.* to 'yourlogin'@'localhost' IDENTIFIED BY 'yourpassword';
    FLUSH PRIVILEGES;
    exit;

  • Next, go into your ~/.boot/dev directory and find the beapi_db.yaml file for editing and change the following lines:
    username: "root"
    password: "password"

    NOTE: you will have to copy this file to the 'test' and 'prod' folders as well.


  • Finally, go into your '/src/main/resources/application.properties' and make sure, that your environment is set to 'dev':
    spring.profiles.active=dev


Build Demo Project

Now that you have everything configured, you will need to build the project. In your gradle.properties, you have three properties (as well as a default variable for setting the 'default configType):

Each 'configType' has a default set of JVMargs (which can be changed) to fit an instance/server type

  • Pass your 'configType' you wish to use in the following command in a shell to build your project :

    gradle clean build -Pargs=configType=nano

Now you are setup and can start running your project...


Run Demo Project

If your database is properly configured and running, you will now need to change your default bootstrapped users.

  • Look in your ~/.boot/{env} dir for a file called 'beapi_api.yaml' (you will want to change this in all environments but change FIRST in the environment your are using right now). In this file you will find the bootstrapping for an ADMIN and a TEST user that are created on startup :
        bootstrap:
            superUser: {
                login: 'admin',
                password: '@6m!nP@s5',
                email: 'email@yourdomain.com'
            }
            testUser: {
                login: 'test',
                password: 't35tP@s5',
                email: 'test@yourdomain.com',
            }

  • Use the superUser login/password to create a curl request to get your token:
    curl -v -H "Content-Type: application/json" -X POST -d '{"username":"admin","password":"@6m!nP@s5"}' http://localhost:8080/authenticate

  • This will return something that looks like the following :
    > GET /v0.4.1/user/show/test HTTP/1.1
    > Host: localhost:8080
    > User-Agent: curl/7.58.0
    > Accept: */*
    > Content-Type: application/json
    > Authorization: Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhZG1pbiIsImV4cCI6MTY2MDA4NzM1OSwiaWF0IjoxNjYwMDY5MzU5fQ.bR8lgrGlzCmHKhXC1D_LF-vVmFINAVX9kgA2n-EiIbslYaix65FXB7qrPRVJxrgqhzNcdTiBOhScbujQwy0ufA
    

  • Everything after 'Bearer' is your TOKEN (not the space of course). Add this to the 'AUTHORIZATION' header with every request you make:
    curl -v -H "Content-Type: application/json" -H "Authorization: Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhZG1pbiIsImV4cCI6MTY2MDA4NzM1OSwiaWF0IjoxNjYwMDY5MzU5fQ.bR8lgrGlzCmHKhXC1D_LF-vVmFINAVX9kgA2n-EiIbslYaix65FXB7qrPRVJxrgqhzNcdTiBOhScbujQwy0ufA" --request GET "http://localhost:8080/v0.4.1/user/show/test"

  • Voila! If all goes well, this will output the 'test' user that was bootstrapped on startup:
    {"firstName":"null","lastName":"null","accountExpired":false,"id":20,"version":2229,"email":"test@yourdomain.com","enabled":true,"username":"test"}


Troubleshooting