위의 이미지는 Rust로 개발한 Unix 스타일의 Redox1 운영체제이다. 현재 개발 단계이며 글 쓴 시점에서 버전은 0.6.0이다. 첫 포스팅에 Redox 이미지를 사용한 이유는 Rust 언어의 성격을 잘 표현해주기 때문이다. 참고로 위의 이미지는 개인 노트북의 VirtualBox에서 실행한 모습이다.
Rust 프로그램에서 HTTP, Rest API(webapi)를 사용하기 위해 reqwest 패키지를 활용한 기본적인 아래의 예제는 blocking 방식과 async로 확장한 방법을 보여준다.
예제에 필요한 기본적인 패키지는 reqwest 외에 tokio, serde를 사용한다. 예제에 사용한 베이스 코드는 Proful Sadangi(Youtube)1를 참고2하였다.
#Cargo.toml
[dependencies]
reqwest = { version = "0.11", features = ["blocking","json"] }
tokio = { version = "1.15.0", features = ["full"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0.74"
#rustfmt.toml
max_width = 200
fn_args_layout = "Compressed"
use_small_heuristics = "Max"
#.cargo/config : static compile option
[target.x86_64-pc-windows-msvc]
rustflags = ["-C", "target-feature=+crt-static"]
Intro to MongoDB with C#1에 이어 이번 주제는 MongoDB와 함께 ASP.NET Core 6 REST API2를 구현하는 예제(Sample)이다. 이전과 마찬가지로 Nuget에서 MongoDB.Driver 패키지를 추가한다.
{
"UserInfoDatabaseSetting": {
"UserInfoCollectionName": "UserInfo",
"ConnectionString": "mongodb://<ID>:<Password>@localhost:27017/?serverSelectionTimeoutMS=5000&connectTimeoutMS=10000&authSource=testdb&authMechanism=SCRAM-SHA-256",
"DatabaseName": "testdb"
},
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}