This application provides endpoints to search and store drug application data, integrating with the OpenFDA API, a PostgreSQL database, and utilizing caching and resilience mechanisms. It also includes OpenAPI documentation.
- Overview
- Prerequisites
- Running the Application Locally
- Building and Testing
- API Documentation
- Endpoints
- Database Migrations
- Caching
- Resilience
- Directory Structure
- Troubleshooting
The OpenFDA API Application allows users to search for drug applications using the OpenFDA API and store these results in a local PostgreSQL database. It leverages caching for improved performance and resilience mechanisms for handling external API failures.
- Java 17: Ensure you have a compatible JDK installed.
- Docker: Required for running the application and its dependencies.
- Docker Compose: Used for orchestrating the application and database.
- Gradle: Used for building and managing the project. You can install it via your package manager (e.g.,
brew install gradle,apt-get install gradle,choco install gradle).
-
Clone the Repository:
git clone https://github.com/vdonets-dev/fda-home-assignment-04 cd fda-home-assignment-04 -
Set Up Environment Variables:
Create a .env file in the root directory with the following content:
OPENFDA_APP_PORT=8080
POSTGRES_DB=openfda_db
POSTGRES_HOST=localhost for native run or db for docker
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
OPENFDA_APP_PORT=8080
PGPORT=5432
POSTGRES_VOLUME=./data/postgres
- Start Services:
docker-compose up --build
- Access the Application:
API Base URL: http://localhost:8080
Build the Application:
./gradlew build
Run Tests:
./gradlew test
| Feature | Description |
|---|---|
| Specification | OpenAPI specification is located at src/main/resources/openapi/openapi.yaml. View this file or use Swagger UI after starting the app. |
| Method | URL | Description | Parameters | Request Body Example |
|---|---|---|---|---|
GET |
/api/drugs/search |
Searches for drug applications. | manufacturer_name (required), brand_name (optional), page (optional, default 0), size (optional, default 10) |
N/A |
GET |
/api/drugs |
Retrieves stored drug applications. | N/A | N/A |
POST |
/api/drugs |
Creates a new drug application. | N/A | json { "application_number": "ANDA203300", "manufacturer_names": ["Pfizer", "Hikma"], "substance_names": ["Atorvastatin"], "product_numbers": ["001"] } |
| Task | Description | Command Example |
|---|---|---|
| Adding Migrations | Add a SQL file in src/main/resources/db/migration/ with a name like V1__description.sql. |
N/A |
| Running Migrations | Use Flyway to apply database migrations. | docker-compose up flyway |
| Provider | Configuration Location | Configuration Example |
|---|---|---|
| Caffeine | application.yml |
yaml caching: caches: openFdaCache: expire-after-write-seconds: 120 initial-capacity: 50 maximum-size: 500 |
| Mechanism | Configuration Location | Configuration Example |
|---|---|---|
| Retry | application.yml |
yaml openfda: api: retry: max-attempts: 3 backoff-interval: 1000 |
| Circuit Breaker | application.yml |
yaml openfda: api: circuit-breaker: name: openfdaCircuitBreaker |