Skip to content
This repository has been archived by the owner on May 14, 2023. It is now read-only.

danilhendrasr/rust-covid-api

Repository files navigation

⚠️ The source API seems to be dead already, so this project is basically unrunnable now.


Rust COVID-19 API

A simple containerized COVID-19 API built using Rust & Actix Web

MIT License LinkedIn

About The Project

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

Why Rust? 🤔

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.

No caching? 😕

Not at the moment.

(back to top)

Getting Started

Running the API

Using Docker

  1. Pull the image from GitHub Container Registry:
    docker pull ghcr.io/danilhendrasr/rust-covid-api:latest
  2. Run the container:
    docker run -d --name rust-covid-api -p 8082:8082 danilhendrasr/rust-covid-api
  3. Access the API via localhost:8082.

Building From Source

Prerequisites
  • Rust 1.57 (used to write this program)
  • pkg-config (for linux system)
  • libssl-dev (for linux system)
Steps
  1. Run the following command:
    cargo run --release
  2. Access the API via localhost:8082.

Running Tests

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.

API Documentation

Go to localhost:8082/docs/ for documentation.

(back to top)

Roadmap

  • 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).

(back to top)

License

Distributed under the MIT License. See LICENSE for more information.

Acknowledgements

(back to top)