Skip to content

A containerized SpringBoot REST API interacting with a containerized PostGres DB

Notifications You must be signed in to change notification settings

mannerheim77/company-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Company API

A simple SpringBoot API demonstrating CRUD operations for a Company, Offices, and Employees. The API is containerized in Docker, and interacts with a containerized PostGres DB.

Technologies

Major technologies used in this app
  • Spring Web MVC - for building annotation-driven RESTful APIs:
    • CompanyController.java - for retrieving and creating companies and offices
    • EmployeeController.java - for retrieving and creating employees
  • Spring Data JPA - for implementation of the Persistence (JPA) and Repository Layers
    • Entities:Company.java, Employee.java, Office.java
    • Repositories: CompanyRepository.java, EmployeeRepository.java, OfficeRepository.java
  • Spring AOP - for implementation of cross-cutting concerns (method performance and method tracing):
    • Timed.java
    • TimedAspect.java
    • Trace.java
    • TraceAspect.java
  • Logger Injection - allows for class-aware injection of org.slf4j.Logger instances
    • LoggerProducer.java, TimedAspect.java
  • Custom Exception Handling - for returning proper RESTful responses when encountering errors
    • CustomExceptionHandler.java
  • Docker - for containerization of the application
    • Dockerfile
  • MapStruct - for auto-generation of DTO/Entity mapper:
    • EntityMapper.java
  • Lombok - for elimination of boilerplate in POJOs, and for implementing builder pattern

Instructions

Installation and Startup Instructions
  1. Clone this repo.
  2. Pull the latest Postgres Docker image:
    $> docker pull postgres
  1. Run the postgres docker image. Choose a new username and password for authentication below
    $> docker run -itd -e POSTGRES_USER=--username-- -e POSTGRES_PASSWORD=--password-- -p 5430:5432 -v /data:/var/lib/postgresql/data --name postgresql postgres
  1. Build the Company API Docker image:
    $> docker build --tag company-api:latest .
  1. Run the Company API Docker image:
    $> docker run -p8887:8080 company-api:latest

**To run standalone (no Docker) run the following:

    $> java -jar build/libs/demo-1.0.0.jar --spring.config.location=src/main/resources/application-dev.yaml

Sample API Requests

Sample API Requests

Create new company

POST http://localhost:8887/api/v1/companies
Content-Type: application/json
Accept: application/json

{
  "name": "Craigs Company"
}

Get all companies

GET http://localhost:8887/api/v1/companies
Content-Type: application/json
Accept: application/json

Create new office

POST http://localhost:8887/api/v1/companies/<id>/offices
Content-Type: application/json
Accept: application/json

{
  "name" : "Dallas Office"
}

Get offices for given company

GET http://localhost:8887/api/v1/companies/<id>/offices
Content-Type: application/json
Accept: application/json

Create new office employee

POST http://localhost:8887/api/v1/offices/<id>/employees
Content-Type: application/json
Accept: application/json

{
  "firstName" : "Craig",
  "lastName" : "Bellamy",
  "emailId" : "[email protected]"
}

About

A containerized SpringBoot REST API interacting with a containerized PostGres DB

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published