A high-performance REST API for date-time operations and timezone conversions built with Rust and Actix-web
✔ Current time retrieval in UTC and Unix timestamp
✔ Date parsing and timezone conversions
✔ Weekday calculations for any date
✔ Support for all major timezone formats
✔ Comprehensive error handling
✔ High-performance async operations
Technology | Purpose |
---|---|
Rust 🦀 | Systems programming language |
Actix-web ⚡ | Web framework |
Chrono 📅 | Date and time handling |
Serde 📦 | Serialization/Deserialization |
First, install Rust using Rustup:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
For more details and platform-specific instructions, visit the official Rust installation page: 🔗 Rust Installation Guide
- Clone the repository:
git clone https://github.com/yourusername/timestamp_microservice.git
cd timestamp_microservice
- Build the project:
cargo build
- Run the tests:
cargo test
- Start the server:
cargo run
The server will start on http://localhost:8080
.
Returns the current time in UTC and Unix timestamp format.
curl http://localhost:8080/api
Response:
{
"unix": 1706400000000,
"utc": "Sun, 28 Jan 2024 00:00:00 GMT",
"timezone": "UTC",
"local_time": "2024-01-28 00:00:00 +0000"
}
curl http://localhost:8080/api/2024-01-28
With timezone:
curl "http://localhost:8080/api/2024-01-28?timezone=America/New_York"
curl http://localhost:8080/api/timezones
Response:
[
"Africa/Abidjan",
"America/New_York",
"Asia/Tokyo",
"Europe/London",
...
]
curl http://localhost:8080/api/weekday/2024-01-28
Response:
{
"weekday": "Sunday"
}
The API uses structured error responses:
{
"type": "InvalidDate",
"message": "input contains invalid characters"
}
Error types:
InvalidDate
: Invalid date formatInvalidTimezone
: Unsupported timezoneInternalError
: Server-side error
Run all tests:
cargo test
Run specific test:
cargo test test_get_weekday
Run tests with output:
cargo test -- --nocapture
/timestamp_microservice
├── src/
│ ├── main.rs # Application entry point
│ ├── error.rs # Error handling
│ └── handlers/ # Request handlers
│ ├── mod.rs # Handler exports
│ ├── time.rs # Time endpoints
│ ├── weekday.rs # Weekday endpoint
│ └── timezones.rs # Timezone endpoint
├── tests/ # Integration tests
├── Cargo.toml # Dependencies
└── README.md # Documentation
# Build the project
cargo build
# Build for release
cargo build --release
# Run the application
cargo run
# Run tests
cargo test
# Check for compilation errors
cargo check
# Update dependencies
cargo update
# Clean build artifacts
cargo clean
- Use
cargo watch
for auto-reloading:cargo install cargo-watch cargo watch -x run
- Format code:
cargo fmt
- Check code style:
cargo clippy
Full API documentation with examples is available in the API.md file.
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
📌 Read the step-by-step guide on my blog:
👉 Building a Timestamp Microservice with Rust and Actix-web
The tutorial covers:
- Setting up a Rust project with Actix-web
- Implementing timezone conversions with chrono
- Error handling best practices
- Writing integration tests
- API documentation
- Performance optimization tips