Rust CalDav Client from Scratch

There are lots of calendar apps to sync calendar data. It’s worth exploring how to use Rust to fetch CalDav data.

Marshal SHI
5 min readNov 11, 2020

--

Image by author

Background

In our daily work, we may use several calendars at the same time, one for group work, one for self-work, one for family TODO, etc… Sometimes it’s hard to follow the schedule. SO, in my company, we created a small python script to fetch all events and TODOs which will happen today, and send an email to everyone in the morning. This is really helpful since it will remind us of the schedule especially we will be noticed in advance and then arrange them more flexibly.

We could do this because it’s easy to create a CalDav client to fetch data from the CalDav server. It’s totally the same as Thunderbird lightning or other calendar apps, they just subscribe to the target calendar via calendar URL. Then apps will automatically fetch new data or post data to the server. But in our use case, we only need to fetch data from the server, filter events, and then send an email out.

In Python, the module caldav is simple to use and get events from the calendar. Just a few lines, we could get today’s events. I won’t post do the tutorial here for caldav module. Please check if you are interested.

But after digging the source code of the Python caldav module, it’s using requests module to fetch data from the server which is used to get/post data from/to an HTTP URL. Then why don’t we try to create a CalDav client via Rust? requests in Python works, then reqwest in Rust will work.

Preparation

There are three things that need to be prepared before starting getting data.

  1. CalDav URL
  2. Username to access
  3. Password for the above username

Requests

CalDav is based on WebDav which is an extension of HTTP. SO, not only some methods which are GET, PUT and DELETE are used in CalDav, but also there are some other extended methods implemented, such as PROPFIND, REPORT, etc… The main methods which we will demo here are the extended methods.

--

--

Marshal SHI

Robots make our life easier | Robotics, Reinforcement Learning, Web, Python, Rust & Life Hacking. At MotivEdge.io