Skip to main content

API Reference

The GztProcessor provides a FastAPI backend with endpoints for managing gazette data and state.

Starting the API

cd gazettes/preprocess
uvicorn main:app --reload

The API will be available at http://127.0.0.1:8000

MinDep Endpoints

State Management

EndpointMethodDescription
/mindep/state/latestGETGet latest saved state (gazette number, date, state)
/mindep/state/{date}GETGet state(s) for a specific date
/mindep/state/{date}/{gazette_number}GETGet specific state by date and gazette number
/mindep/state/resetDELETEDelete all MinDep state files and DB

Gazette Processing

EndpointMethodDescription
/mindep/initial/{date}/{gazette_number}GETPreview contents of initial gazette
/mindep/initial/{date}/{gazette_number}POSTCreate initial state in DB and save snapshot
/mindep/amendment/{date}/{gazette_number}GETDetect transactions from amendment
/mindep/amendment/{date}/{gazette_number}POSTApply confirmed transactions to DB

Example: Create Initial State

Request:

curl -X POST "http://127.0.0.1:8000/mindep/initial/2022-07-22/2289-43" \
-H "Content-Type: application/json" \
-d '{
"ministers": [
{
"name": "Ministry of Finance",
"departments": [
{ "name": "Department of Treasury" },
{ "name": "Inland Revenue" }
]
}
]
}'

Example: Apply Amendment

Request:

curl -X POST "http://127.0.0.1:8000/mindep/amendment/2022-09-16/2297-78" \
-H "Content-Type: application/json" \
-d '{
"transactions": {
"moves": [],
"adds": [
{ "ministry": "Ministry of Finance", "department": "New Dept" }
],
"terminates": []
}
}'

Person Endpoints

State Management

EndpointMethodDescription
/person/state/latestGETGet latest saved persons and portfolios
/person/state/{date}GETGet state(s) for a specific date
/person/state/{date}/{gazette_number}GETGet specific person state by date and gazette number
/person/state/resetDELETEDelete all Person state files and DB

Gazette Processing

EndpointMethodDescription
/person/{date}/{gazette_number}GETPreview predicted transactions from person gazette
/person/{date}/{gazette_number}POSTApply reviewed transactions to DB

Example: Apply Person Transactions

Request:

curl -X POST "http://127.0.0.1:8000/person/2022-07-22/2067-09" \
-H "Content-Type: application/json" \
-d '{
"transactions": {
"moves": [],
"adds": [
{
"person": "Hon. John Doe",
"ministry": "Ministry of Finance",
"position": "Minister"
}
],
"terminates": []
}
}'

Transaction Endpoints

EndpointMethodDescription
/transactions/GETGet all transactions

Health Check

EndpointMethodDescription
/GETHealth check/status message

Function Mapping

Endpoint TypeMain Functions CalledPurpose
MinDep Initialextract_initial_gazette_data, load_initial_state_to_dbExtract/load initial ministry structure
MinDep Amendmentprocess_amendment_gazette, apply_transactions_to_dbDetect/apply department changes
Person Gazetteprocess_person_gazette, apply_transactions_to_dbDetect/apply person-portfolio changes
State Managementget_latest_state, get_state_by_date, load_state, clear_all_state_dataManage and reset state snapshots

Error Handling

The API returns JSON error messages for:

  • Missing files
  • Invalid requests
  • Resources not found

Always check the response for an error key if your request fails.

{
"error": "State file not found for date 2022-01-01"
}