A simple containerized COVID-19 API built using Rust & Actix Web
In order to participate in Nodeflux's internship program as a software engineer, applicants were required to complete a technical assessment. We were tasked to build a containerized COVID-19 API using either C++, Rust, or Python. This project is made to complete the said technical assessment.
This API is only a mask API, the data source is https://data.covid19.go.id/public/api/update.json, it is a COVID-19 API seemingly provided by the Indonesian government, but the design is not quite good because it only provides 1 endpoint and the only respond it provides is in a daily format containing all daily cases since the begining of COVID-19.
This API provides a more friendly interface, users can get the data in daily, monthly, and yearly format as well as search for specific date, month, and/or year.
The following is the diagram:
sequenceDiagram
participant Client
participant This API
participant Data Source
Client->>This API: request monthly cases
This API->>Data Source: send get request
Data Source->>This API: send JSON response
This API->>This API: convert response to monthly format
This API->>Client: send monthly cases
Initially the reason for choosing Rust was because I presume it's more impressive in the recruiter's eyes if I built it using Rust and so that I can treat it as my Rust learning playground as well.
But looking back, I think one more reason I can add to that is Rust is fast in doing CPU-heavy operations, which is what this API does on a regular basis (converting quite large amount of data into another form). On the other hand, Python is not as fast in doing such operations and C++ is too hard for a beginner like to get productive quickly, thus in my opinion Rust is the ideal choice for this one.
Not at the moment.
- Pull the image from GitHub Container Registry:
docker pull ghcr.io/danilhendrasr/rust-covid-api:latest
- Run the container:
docker run -d --name rust-covid-api -p 8082:8082 danilhendrasr/rust-covid-api
- Access the API via localhost:8082.
- Rust 1.57 (used to write this program)
- pkg-config (for linux system)
- libssl-dev (for linux system)
- Run the following command:
cargo run --release
- Access the API via localhost:8082.
Run the following command:
cargo test
Note
Some tests might fail when being run in a certain situation.For example, the test for yearly endpoints might fail if it's being run on the first day of a new year because the code uses the current date and time to determine the latest date and time, while the source API might haven't updated its data. This should be fixed once the caching mechanism is in place though.
Go to localhost:8082/docs/ for documentation.
- Complete the refactoring
- Create automated deployment pipeline
- Add just enough tests
- Add API docs using Swagger UI
- Implement caching mechanism
See the open issues for a full list of proposed features (and known issues).
Distributed under the MIT License. See LICENSE for more information.