RustLang.kr 웹사이트, 블로그를 오픈하였습니다. rust language를 스터디한 후 정리한 내용을 Tutorial 형태로 연재할 생각입니다.
내용은 rust 언어의 키워드 중심으로 꾸며질 예정입니다. 실제 서비스에 필요한 내용(Web API1 etc)도 추가로 포스팅할 수 있습니다. 올해는 개인적인 프로그래밍 언어의 스킬업 Skill up을 위해 Rust 언어를 집중적으로 학습하기 때문에 당분간 MSJO.kr 사이트에 글쓰기는 자제할 생각입니다.
당분간 새로운 글은 RustLang.kr에서 확인해 주세요.
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": "*"
}