This application provides information about seaports.
The app consists of two services:
- ClientAPI (
api
)- parse JSON file with ports data
- interact with PortDomainService to save it
- provide REST API
- PortDomainService (
repository
)- saving ports data and retrieving it from the database
ClientAPI communicates with PortDomainService via gRPC.
-
To populate database with initial seaports data, add
ports.json
file todata
directory. It should contain JSON object of the following format:{ "AEAJM": { "name": "Ajman", "city": "Ajman", "country": "United Arab Emirates", "alias": [], "regions": [], "coordinates": [ 55.5136433, 25.4052165 ], "province": "Ajman", "timezone": "Asia/Dubai", "unlocs": [ "AEAJM" ], "code": "52000" }, ... }
-
Docker images of both services are on DockerHub, so you only need
docker-compose
to run this project:make run
-
Now, you can use ClientAPI to CRUD seaports
curl '127.0.0.1:8080/ports?limit=2&offset=12'
Fetching ports:
GET /ports?limit={limit}&offset={offset}
required limit is a maximum number of ports returned optional offset is a number of ports to skip (0 if not set)
Creating the port:
POST /ports
Port info should be supplied in the request body. Example:
{
"id": "AEAJM",
"name": "Ajman",
"city": "Ajman",
"country": "United Arab Emirates",
"alias": [],
"regions": [],
"coordinates": [
55.5136433,
25.4052165
],
"province": "Ajman",
"timezone": "Asia/Dubai",
"unlocs": [
"AEAJM"
],
"code": "52000"
}
Fetching the port:
GET /ports/{id}
Updating the port:
PUT /ports/{id}
Fields you want to update should be supplied in the request body. Example:
{
"country": "United Arab Emirates",
"province": "Ajman"
}
Deleting the port:
DELETE /ports/{id}
You can build images manually:
- To build
client-api
image:make api
- To build
port-domain-service
image:make repository
You can control services configuration with environment variables.
Environment variable | Default value | Description |
---|---|---|
REPOSITORY | repository:8080 | PortDomainService address |
DATA_FILE | /opt/api/data/ports.json | file with ports data for initial population |
PORT | 8080 | port service should listen |
Environment variable | Default value | Description |
---|---|---|
MONGO_URL | mongo:27017 | MongoDB address |
MONGO_DB | ports | MongoDB database to use |
MONGO_COLLECTION | ports | MongoDB collection |
PORT | 8080 | port service should listen |
- Add tests for gRPC client and server
- Add logging for PortDomainService
- Convert gRPC error to REST error