rohanreddymelachervu / SpringBoot-Animal-Facts-APIs

Chatment-SpringBoot-Animal-Facts-APIs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SpringBoot-Animal-Facts-APIs

SpringBoot-Animal-Facts-APIs
Endpoints:

  1. Get Animal Fact: POST to http://<localhost/IP>:(port)/getFact with POST body of JSON {"animalName":"<animal_name>"} replace animal_name with either cat or dog. This endpoint returns a random fact about that animal and logs access info to Access Log Entity in the Embedded H2 DataBase which is in-memory (non persistent). example POST request for this project: http://192.168.0.108:8081/getFact with POST Body as {"animalType":"dog"}
  2. Get Access Log Info: GET to http://<localhost/IP>:(port)/access/log) and add a header with Key: "Authorization" and Value: "chatment-access-log-api-key-hlTYXuavbTbxWRARrhvRj112i6zBbEBhtHwUdUGvUbhv0fO6uOhtVyHAxKJFIvVV8aqIPVbWQLdTwJZ0oMV3BLK8ypRnd3s3bhug" (this API Key is read by a custom filter from the application.properties file and verified within this). This endpoint returns all the data from Access Log Entity from the Embedded DataBase.
  3. Access Log API-Key is configured in application.properties of Spring Boot in src\main\resources. It is used by ChatmentAccessLogFilter for access log API authentication.
  4. ChatmentAccessLogFilter is a custom filter which intercepts the http request and authenticates request to the endpoint /access/log using APi-Key in the request header.
  5. The Embedded in-memory H2 database has 4 tables: animal_traits, cat_traits, dog_traits and access_log. The animal_traits table was designed for combined animal facts which is deprecated in this release. The other 3 tables are used in this project.
    schema.sql and data.sql are database initialization files which are placed under src/main/resources.
    Database can be accessed via web console at http://<localhost/IP:(port)/h2-console access details are
    Driver class: org.h2.Driver
    JDBC URL: jdbc:h2:mem:animal_traits_db
    User Name: rohan
    Password: password
    Steps to run project:
    1.) Navigate to directory of the project.
    2.) execute mvn install -DskipTests
    3.) Now go to directory of the jar file
    4.) execute java -jar <filename.jar>
    5.) Use PostMan to send POST or GET requests to specific endpoints.

(C) Rohan Reddy Melachervu - 2022

About

Chatment-SpringBoot-Animal-Facts-APIs

License:Apache License 2.0


Languages

Language:Java 100.0%