{"id":11736,"date":"2024-01-18T02:06:04","date_gmt":"2024-01-17T17:06:04","guid":{"rendered":"https:\/\/www.webcyou.com\/?p=11736"},"modified":"2024-01-18T02:06:09","modified_gmt":"2024-01-17T17:06:09","slug":"rust-actix-web-x-mongodb%e7%92%b0%e5%a2%83%e3%82%92%e3%82%b5%e3%82%af%e3%83%83%e3%81%a8%e8%b5%b7%e5%8b%95","status":"publish","type":"post","link":"https:\/\/www.webcyou.com\/?p=11736","title":{"rendered":"Rust &#8211; Actix Web \u00d7 MongoDB\u74b0\u5883\u3092\u30b5\u30af\u30c3\u3068\u8d77\u52d5"},"content":{"rendered":"\n<p>\u3069\u3082\u3067\u3059\u3002<\/p>\n<p>\u6628\u5e74\u3088\u308a\u696d\u52d9\u3067\u30ac\u30c3\u30c4\u30eaRust\u3067\u306e\u958b\u767a\u3092\u884c\u3063\u3066\u306f\u3044\u308b\u306e\u3067\u3059\u304c\u3001\u4e3b\u306b\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u30a2\u30d7\u30ea\u958b\u767a\u306e\u65b9\u3067\u3001\u305d\u3046\u3044\u3048\u3070\u30b5\u30fc\u30d0\u30fc\u5468\u308a\u306f\u3069\u3046\u306a\u3063\u3066\u3044\u308b\u306e\u3060\u308d\u3046\u3068\u3001\u6700\u8fd1\u306f\u3082\u3054\u3082\u3054\u6f01\u3063\u3066\u3044\u308b\u72b6\u6cc1\u3060\u3063\u305f\u308a\u3057\u307e\u3059\u3002<\/p>\n<p>Rust\u306easync\u5bfe\u5fdc\u3082\u7d42\u308f\u308a\u3001\u30b5\u30fc\u30d0\u30fc\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u306e\u65b9\u3082\u5b89\u5b9a\u4e14\u3064\u3001\u5897\u3048\u3066\u6765\u3066\u3044\u308b\u72b6\u6cc1\u3067\u3001\u5168\u7136Rust\u3067\u306e\u30b5\u30fc\u30d0\u30fc\u958b\u767a\u306f\u30a2\u30ea\u3060\u306a\u3068\u611f\u3058\u3066\u3044\u308b\u4eca\u65e5\u3053\u306e\u3054\u308d\u3067\u3059\u3002<\/p>\n<p>\u3068\u3044\u3046\u304b\u3001\u30b5\u30fc\u30d0\u30fc\u958b\u767a\u3067\u4f7f\u308f\u306a\u3044\u7406\u7531\u306e\u5c11\u306a\u3055\u3082\u3042\u3063\u3066\u3001\u3080\u3057\u308d\u7a4d\u6975\u7684\u306b\u30b5\u30fc\u30d0\u30fc\u958b\u767a\u306bRust\u63a1\u7528\u3057\u3066\u3044\u304f\u3079\u304d\u3060\u3068\u601d\u3044\u307e\u3059\u3057\u3001\u4eca\u5f8c\u3082\u5897\u3048\u3066\u3044\u304f\u306e\u3060\u308d\u3046\u3068\u808c\u611f\u3067\u611f\u3058\u307e\u3057\u305f\u3002<\/p>\n<p>\u3068\u3044\u3046\u8a33\u3067\u3001\u4eca\u65e5\u306f\u3001<strong>Rust\u306e\u30b5\u30fc\u30d0\u30fc\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u306eActix Web\u3092\u7528\u3044\u3066\u3001DB\u306fmongodb\u3067\u30ed\u30fc\u30ab\u30eb\u958b\u767a\u74b0\u5883\u3092\u30b5\u30af\u30c3\u3068\u8d77\u3061\u4e0a\u3052\u3066\u884c\u304d\u305f\u3044<\/strong>\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>\u00a0<\/p>\n<h4>Homebrew\u3067MongoDB\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<!-- notionvc: 1395ea1c-a234-4259-a0a6-0913434ed79a --><\/h4>\n<p>Homebrew\u3067MongoDB\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u3066\u3044\u304d\u307e\u3059\u3002\u3053\u306e\u8fba\u89e3\u8aac\u306f\u5272\u611b\u3055\u305b\u3066\u3044\u305f\u3060\u304d\u307e\u3059\u3002<!-- notionvc: 84e57c77-f404-4b10-b717-7de981e9c162 --><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"bash\">brew tap mongodb\/brew<\/pre>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"bash\">brew install mongodb-community<\/pre>\n<p><strong><span class=\"notion-enable-hover\" data-token-index=\"0\">\u30d0\u30fc\u30b7\u30e7\u30f3\u306e\u78ba\u8a8d<\/span><\/strong><!-- notionvc: cbe54c55-bc57-4e22-8e8d-737f9d2760a6 --><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">mongod --version<\/pre>\n<p><strong><span class=\"notion-enable-hover\" data-token-index=\"0\">\u8d77\u52d5\u30fb\u505c\u6b62\u65b9\u6cd5\u306e\u78ba\u8a8d<\/span><\/strong><!-- notionvc: e4888883-0bd2-43e7-9b61-5dbc87b0aba6 --><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"bash\">brew services start mongodb-community<\/pre>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"bash\">brew services stop mongodb-community<\/pre>\n<p>\u00a0<\/p>\n<h4>MongoDB compass\u3067DB\u4f5c\u6210<!-- notionvc: 9f2b02f7-dc18-4387-826d-dbe7e4f88aaa --><\/h4>\n<p>MongoDB\u306eGUI\u30c4\u30fc\u30eb\u306eMongoDB compass\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>\u3053\u3061\u3089\u306f\u4efb\u610f\u3067\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u3066\u3044\u305f\u3060\u3051\u308c\u3070\u3068\u3002cli\u3067\u884c\u3046\u65b9\u306f\u98db\u3070\u3057\u3066\u9802\u3044\u3066\u554f\u984c\u3042\u308a\u307e\u305b\u3093\u3002<\/p>\n<p>MongoDB compass\u516c\u5f0f\u306eHP\u3088\u308a<a href=\"https:\/\/www.mongodb.com\/ja-jp\/products\/tools\/compass\">compass<\/a>\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<p><!-- notionvc: c63bde14-208f-4485-83e4-4f1e27cebbda --><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone  wp-image-11737\" src=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/2024\/01\/mongo1-1024x516.png\" alt=\"\" width=\"616\" height=\"310\" srcset=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/2024\/01\/mongo1-1024x516.png 1024w, https:\/\/www.webcyou.com\/wp-content\/uploads\/2024\/01\/mongo1-300x151.png 300w, https:\/\/www.webcyou.com\/wp-content\/uploads\/2024\/01\/mongo1-768x387.png 768w, https:\/\/www.webcyou.com\/wp-content\/uploads\/2024\/01\/mongo1-1536x775.png 1536w, https:\/\/www.webcyou.com\/wp-content\/uploads\/2024\/01\/mongo1-2048x1033.png 2048w\" sizes=\"auto, (max-width: 616px) 100vw, 616px\" \/><\/p>\n<p>\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u30da\u30fc\u30b8\u306f\u4ee5\u4e0b\u306b\u306a\u308a\u307e\u3059\u3002\u8a72\u5f53\u3059\u308bPlatform\u3092\u9078\u629e\u3057\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<p><a href=\"https:\/\/www.mongodb.com\/try\/download\/compass\">\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u30da\u30fc\u30b8<\/a><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone  wp-image-11738\" src=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/2024\/01\/mongo2-1024x697.png\" alt=\"\" width=\"452\" height=\"308\" srcset=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/2024\/01\/mongo2-1024x697.png 1024w, https:\/\/www.webcyou.com\/wp-content\/uploads\/2024\/01\/mongo2-300x204.png 300w, https:\/\/www.webcyou.com\/wp-content\/uploads\/2024\/01\/mongo2-768x523.png 768w, https:\/\/www.webcyou.com\/wp-content\/uploads\/2024\/01\/mongo2.png 1472w\" sizes=\"auto, (max-width: 452px) 100vw, 452px\" \/><\/p>\n<p><!-- notionvc: f8a8acde-e088-417d-b73e-3e37e093bce9 --><\/p>\n<p>brew\u30b3\u30de\u30f3\u30c9\u3067mongodb\u3092\u8d77\u52d5\u3057\u307e\u3057\u305f\u3089\u3001MongoDB compass\u300cmongodb:\/\/localhost:27017\u300d\u3067\u63a5\u7d9a\u3002\uff0b\u30a2\u30a4\u30b3\u30f3\u3067\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u300cmyApp\u300d\u3092\u4f5c\u6210\u3001\u5de6\u4e0a\u306e\u300c+ Create collection\u300d\u30dc\u30bf\u30f3\u3092\u62bc\u4e0b\u3001Collection Name\u300cusers\u300d\u3067\u3001\u300cCreate collection\u300d\u30dc\u30bf\u30f3\u3092\u62bc\u4e0b\u3002<!-- notionvc: 079e6cb7-cc4d-403e-a00f-170e58dbb78a --><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone  wp-image-11739\" src=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/2024\/01\/mongo3-1024x693.png\" alt=\"\" width=\"470\" height=\"318\" srcset=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/2024\/01\/mongo3-1024x693.png 1024w, https:\/\/www.webcyou.com\/wp-content\/uploads\/2024\/01\/mongo3-300x203.png 300w, https:\/\/www.webcyou.com\/wp-content\/uploads\/2024\/01\/mongo3-768x520.png 768w, https:\/\/www.webcyou.com\/wp-content\/uploads\/2024\/01\/mongo3.png 1276w\" sizes=\"auto, (max-width: 470px) 100vw, 470px\" \/><\/p>\n<p>\u3053\u308c\u3067\u3001DB\u540d\u300cmyApp\u300d\u3001collection\u306f\u300cusers\u300d\u306e\u5f62\u3067\u3001\u6e96\u5099\u304c\u5b8c\u4e86\u3002<!-- notionvc: e72e99f9-609f-4804-9a96-0a9da7ef63f2 --><\/p>\n<p>\u00a0<\/p>\n<h4>Actix Web<!-- notionvc: b6ae0987-e8c2-4dae-b7b9-c460e8ee3b48 --><\/h4>\n<p>\u305d\u308c\u3067\u306f\u3001Actix Web\u3068mongodb\u3092\u7528\u3044\u3066\u3001API\u3092\u4f5c\u3063\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<p>\u307e\u305a\u306f\u3001cargo new\u3067\u65b0\u898f\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u4f5c\u6210\u3002<\/p>\n<p><!-- notionvc: 450afaaa-7c64-4498-90ff-684f691d46f1 --><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"bash\">cargo new mongodb --bin<\/pre>\n<p>create\u306f\u4ee5\u4e0b\u306e3\u3064\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002<!-- notionvc: 0be53c15-3241-4204-8f57-7cd170b79534 --><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"bash\">[dependencies]\nmongodb = \"2\"\nactix-web = \"^4\"\nserde = { version = \"^1\", features = [\"derive\"] }<\/pre>\n<p>\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u66f8\u3044\u3066\u884c\u304f\u306e\u3067\u3059\u304c\u3001Actix Web\u306f\u30b5\u30f3\u30d7\u30eb\u304c\u8c4a\u5bcc\u3067\u3001mongodb\u3092\u7528\u3044\u305f\u30b5\u30f3\u30d7\u30eb\u3082\u4ee5\u4e0b\u306b\u5b58\u5728\u3057\u307e\u3059\u3002\u306a\u306e\u3067\u3001\u30bd\u30fc\u30b9\u3060\u3051\u77e5\u308a\u305f\u3044\u65b9\u306f\u3001\u3053\u3061\u3089\u3092\u898b\u3066\u3044\u305f\u3060\u3051\u308c\u3070\u3068\u3002<\/p>\n<p><strong>GitHub<\/strong><\/p>\n<p><a href=\"https:\/\/github.com\/actix\/examples\/blob\/master\/databases\/mongodb\/src\/main.rs\">actix\/examples<\/a><\/p>\n<p><!-- notionvc: be4485d2-3d70-4aec-90ec-e6588d948366 -->examples\u306e\u30bd\u30fc\u30b9\u3092\u8ffd\u3063\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002\u307e\u305a\u306f\u300csrc\/model.rs\u300d\u3067\u3059\u304c\u3001struct User\u3092\u5b9a\u7fa9\u3057\u3066\u304a\u308a\u307e\u3059\u3002<!-- notionvc: 13683ff8-058e-4d69-86ad-ee2b3cc960ad --><\/p>\n<p>User Model: src\/model.rs<!-- notionvc: 20668520-2525-46e8-8692-bd52347bd6f3 --><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"rust\">pub struct User {\n    pub first_name: String,\n    pub last_name: String,\n    pub username: String,\n    pub email: String,\n}<\/pre>\n<p>\u00a0<\/p>\n<p>\u306f\u3044\u3002\u5f8c\u306f\u300c<a href=\"http:\/\/main.rs\">main.rs<\/a>\u300d\u3068\u306a\u308a\u307e\u3059\u3002create\u306e\u30a4\u30f3\u30dd\u30fc\u30c8\u3084\u3001\u5b9a\u6570\u3092\u5b9a\u7fa9\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>\u5148\u7a0b\u306eDB\u540d\u3001collection\u540d\u3082\u3053\u3061\u3089\u3067\u5b9a\u7fa9\u3057\u3066\u304a\u308a\u307e\u3059\u3002<\/p>\n<p><!-- notionvc: 47c6660e-4c31-42a8-8c8a-0fd26001d9ed --><\/p>\n<p>src\/main.rs<!-- notionvc: 9c8d6b4b-dca2-42d1-b20b-1828dadddd67 --><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"rust\">mod model;\n\nuse actix_web::{get, post, web, App, HttpResponse, HttpServer};\nuse model::User;\nuse mongodb::{bson::doc, options::IndexOptions, Client, Collection, IndexModel};\n\nconst DB_NAME: &amp;str = \"myApp\";\nconst COLL_NAME: &amp;str = \"users\";<\/pre>\n<p>\u00a0<\/p>\n<p>Actix Web\u3067\u306f\u3001#[post(&#8220;\/add_user&#8221;)]\u3068\u3044\u3063\u305f\u30a2\u30c8\u30ea\u30d3\u30e5\u30fc\u30c8\u3067\u306eAPI\u306e\u5b9a\u7fa9\u3092\u884c\u3046\u3053\u3068\u304c\u53ef\u80fd\u3067\u3059\u3002\u4ee5\u4e0b\u306e\u5834\u5408\u306f \/add_user\u306eURI\u306b\u5bfe\u3057\u3066\u3001add_user\u95a2\u6570\u3092\u5b9f\u884c\u3057\u3001\u30e6\u30fc\u30b6\u30fc\u3092\u4f5c\u6210\u3059\u308b\u51e6\u7406\uff08API\uff09\u3068\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>mongodb\u3067\u3042\u308b\u3001client\u3092\u5f15\u6570collection\u306b\u30a2\u30af\u30bb\u30b9\u3057\u3001\u30e6\u30fc\u30b6\u30fc\u3092\u4f5c\u6210\u3002\u5931\u6557\u3057\u305f\u3089\u30a8\u30e9\u30fc\u3068\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u30e6\u30fc\u30b6\u30fc\u4f5c\u6210 POST: \/add_user<\/p>\n<p><!-- notionvc: 7a569be7-8caf-471f-ad21-a923c22cf99e --><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"rust\">\/\/\/ Adds a new user to the \"users\" collection in the database.\n#[post(\"\/add_user\")]\nasync fn add_user(client: web::Data&lt;Client&gt;, form: web::Form&lt;User&gt;) -&gt; HttpResponse {\n    let collection = client.database(DB_NAME).collection(COLL_NAME);\n    let result = collection.insert_one(form.into_inner(), None).await;\n    match result {\n        Ok(_) =&gt; HttpResponse::Ok().body(\"user added\"),\n        Err(err) =&gt; HttpResponse::InternalServerError().body(err.to_string()),\n    }\n}<\/pre>\n<p>\u3053\u3061\u3089\u306f\u3001\u30e6\u30fc\u30b6\u30fc\u3092\u53c2\u7167\u3059\u308bAPI\u3068\u306a\u308a\u307e\u3059\u3002username\u3092URI\u306b\u542b\u3081\u3001DB\u3092\u63a2\u7d22\u3057\u8a72\u5f53\u3059\u308b\u30e6\u30fc\u30b6\u30fc\u3092\u53d6\u5f97\u3057\u307e\u3059\u3002<\/p>\n<p>username\u306b\u95a2\u3057\u3066\u306funique\u3068\u3057\u3066\u8a2d\u5b9a\u3055\u308c\u3066\u3044\u307e\u3059\u306e\u3067\u3001\u91cd\u8907\u306f\u60f3\u5b9a\u3057\u3066\u3044\u306a\u304ffind_one\u3067\u53d6\u5f97\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p><!-- notionvc: f5ae22b3-9c5f-4024-852f-82ec4452b814 -->\u30e6\u30fc\u30b6\u30fc\u53c2\u7167 GET: \/get_user\/{username}<!-- notionvc: 50f3c305-4a9e-447a-9004-41d961b8d131 --><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"rust\">\/\/\/ Gets the user with the supplied username.\n#[get(\"\/get_user\/{username}\")]\nasync fn get_user(client: web::Data&lt;Client&gt;, username: web::Path&lt;String&gt;) -&gt; HttpResponse {\n    let username = username.into_inner();\n    let collection: Collection&lt;User&gt; = client.database(DB_NAME).collection(COLL_NAME);\n    match collection\n        .find_one(doc! { \"username\": &amp;username }, None)\n        .await\n    {\n        Ok(Some(user)) =&gt; HttpResponse::Ok().json(user),\n        Ok(None) =&gt; {\n            HttpResponse::NotFound().body(format!(\"No user found with username {username}\"))\n        }\n        Err(err) =&gt; HttpResponse::InternalServerError().body(err.to_string()),\n    }\n}<\/pre>\n<p>\u30b5\u30fc\u30d0\u30fc\u8d77\u52d5\u6642\u306bcreate_username_index\u95a2\u6570\u3092\u547c\u3073\u3001\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u304b\u3089Documents\u306eusername\u306b\u5bfe\u3057\u3066index\u8a2d\u5b9a\u3092\u884c\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u306a\u306e\u3067\u3001mongodb\u5074\u3067index\u3092\u5916\u3057\u30e6\u30cb\u30fc\u30af\u3067\u306f\u7121\u304f\u306a\u3063\u3066\u3044\u305f\u308a\u3059\u308b\u3068\u3001\u30a8\u30e9\u30fc\u3068\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>index\u51e6\u7406<\/p>\n<p><!-- notionvc: 41533381-5291-40ad-999c-80bc6cfcbad5 --><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"rust\">create_username_index(&amp;client).await;\n\n\/\/\/ Creates an index on the \"username\" field to force the values to be unique.\nasync fn create_username_index(client: &amp;Client) {\n    let options = IndexOptions::builder().unique(true).build();\n    let model = IndexModel::builder()\n        .keys(doc! { \"username\": 1 })\n        .options(options)\n        .build();\n    client\n        .database(DB_NAME)\n        .collection::&lt;User&gt;(COLL_NAME)\n        .create_index(model, None)\n        .await\n        .expect(\"creating an index should succeed\");\n}<\/pre>\n<p>main\u306e\u51e6\u7406\u306f\u3001mongodb\u306b\u30a2\u30af\u30bb\u30b9\u3068\u3001HttpServer::new\u3067\u30b5\u30fc\u30d0\u30fc\u3092\u8d77\u3061\u4e0a\u3052\u3001App::new()\u3067mongodb\u306e\u30c7\u30fc\u30bf\u3092app data\u5316\u3002\u5148\u7a0b\u306eAPI\u3092service\u5316\u3092\u884c\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u4ee5\u4e0b\u306e\u74b0\u5883\u3067\u8d77\u52d5\u3002<\/p>\n<p><strong>\u30b5\u30fc\u30d0\u30fc<\/strong><\/p>\n<p><a href=\"http:\/\/127.0.0.1:8080\">http:\/\/127.0.0.1:8080<\/a><\/p>\n<p>M<strong>ongoDB<\/strong><\/p>\n<p>mongodb:\/\/localhost:27017<\/p>\n<p><!-- notionvc: 8ff8b950-f517-4052-a091-fd078f16910f --><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"rust\">#[actix_web::main]\nasync fn main() -&gt; std::io::Result&lt;()&gt; {\n    let uri = std::env::var(\"MONGODB_URI\").unwrap_or_else(|_| \"mongodb:\/\/localhost:27017\".into());\n\n    let client = Client::with_uri_str(uri).await.expect(\"failed to connect\");\n    create_username_index(&amp;client).await;\n\n    HttpServer::new(move || {\n        App::new()\n            .app_data(web::Data::new(client.clone()))\n            .service(add_user)\n            .service(get_user)\n    })\n    .bind((\"127.0.0.1\", 8080))?\n    .run()\n    .await\n}<\/pre>\n<p>\u305d\u308c\u3067\u306f\u3001cargo run\u3067\u8d77\u52d5\u3057\u307e\u3057\u3087\u3046\u3002<!-- notionvc: 2b66f913-7721-4f13-8820-69abe4501b35 --><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"bash\">cargo run<\/pre>\n<h4>API\u758e\u901a\u30c6\u30b9\u30c8<\/h4>\n<p><a href=\"https:\/\/www.postman.com\/\">Postman<\/a>\u3092\u7528\u3044\u3066API\u758e\u901a\u30c6\u30b9\u30c8\u3092\u884c\u3044\u307e\u3059\u3002\u307e\u305a\u306f\u3001\u30e6\u30fc\u30b6\u30fc\u4f5c\u6210\u3057\u305f\u3044\u306e\u3067\u3001POST\u306b\u8a2d\u5b9a\u3067<\/p>\n<p>URI\u306f\u300c<a href=\"http:\/\/127.0.0.1:8080\/add_user%E3%80%8D%E5%85%A5%E5%8A%9B%E3%80%82\">http:\/\/127.0.0.1:8080\/add_user\u300d\u5165\u529b\u3002<\/a><\/p>\n<p>Body\u306fJSON\u5f62\u5f0f\u3067\u4ee5\u4e0b\u306e\u30c7\u30fc\u30bf\u3092\u9001\u4fe1\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone  wp-image-11740\" src=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/2024\/01\/mongo4-1024x447.png\" alt=\"\" width=\"579\" height=\"253\" srcset=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/2024\/01\/mongo4-1024x447.png 1024w, https:\/\/www.webcyou.com\/wp-content\/uploads\/2024\/01\/mongo4-300x131.png 300w, https:\/\/www.webcyou.com\/wp-content\/uploads\/2024\/01\/mongo4-768x336.png 768w, https:\/\/www.webcyou.com\/wp-content\/uploads\/2024\/01\/mongo4.png 1460w\" sizes=\"auto, (max-width: 579px) 100vw, 579px\" \/><\/p>\n<p>\u30e6\u30fc\u30b6\u30fc\u4f5c\u6210 POST: \/add_user<!-- notionvc: 24b99f26-f9b2-4304-a269-43e77fa3aa26 --><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"json\">{\n    \"first_name\": \"daisuke\",\n    \"last_name\": \"takayama\",\n    \"username\": \"takayama_daisuke\",\n    \"email\": \"webcyou@webcyou.com\",\n}<\/pre>\n<p>\u30a8\u30e9\u30fc\u304c\u51fa\u306a\u3051\u308c\u3070\u6210\u529f\u3002\u3067\u306f\u3001\u4f5c\u6210\u3057\u305f\u30e6\u30fc\u30b6\u30fc\u3092\u53d6\u5f97\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>\u30e6\u30fc\u30b6\u30fc\u53d6\u5f97\u306fGET\u3067\u3001URI\u3092\u53d6\u5f97\u3057\u305f\u3044\u30e6\u30fc\u30b6\u30fc\u540d\u3082\u542b\u3081\u305f\u300c<a href=\"http:\/\/127.0.0.1:8080\/get_user\/takayama_daisuke%E3%80%8D%E3%82%92%E5%85%A5%E5%8A%9B%E3%80%82\">http:\/\/127.0.0.1:8080\/get_user\/takayama_daisuke\u300d\u3092\u5165\u529b\u3002<\/a><\/p>\n<p><!-- notionvc: e44538e1-5427-4bee-9ad0-62572f8413c4 --><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone  wp-image-11741\" src=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/2024\/01\/mongo5-869x1024.png\" alt=\"\" width=\"396\" height=\"467\" srcset=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/2024\/01\/mongo5-869x1024.png 869w, https:\/\/www.webcyou.com\/wp-content\/uploads\/2024\/01\/mongo5-255x300.png 255w, https:\/\/www.webcyou.com\/wp-content\/uploads\/2024\/01\/mongo5-768x905.png 768w, https:\/\/www.webcyou.com\/wp-content\/uploads\/2024\/01\/mongo5.png 956w\" sizes=\"auto, (max-width: 396px) 100vw, 396px\" \/><\/p>\n<p>\u30e6\u30fc\u30b6\u30fc\u53c2\u7167 GET: \/get_user\/{username}<\/p>\n<p>\u30ec\u30b9\u30dd\u30f3\u30b9\u306b\u8a72\u5f53\u3059\u308b\u30e6\u30fc\u30b6\u30fc\u304cJSON\u5f62\u5f0f\u3067\u8fd4\u5374\u3055\u308c\u308c\u3070\u6210\u529f\u3002<\/p>\n<p><!-- notionvc: aae9c900-14da-4877-adbb-3769e5a0f21f --><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"json\">{\n    \"first_name\": \"daisuke\",\n    \"last_name\": \"takayama\",\n    \"username\": \"takayama_daisuke\",\n    \"email\": \"webcyou@webcyou.com\"\n}<\/pre>\n<p>\u3068\u3001\u4e00\u65e6\u3053\u3053\u307e\u3067\u3067\u8d77\u52d5\u306f\u6210\u529f\u3002<\/p>\n<p>\u3044\u3084\u3041\u3002\u7206\u901f\u306e\u30b5\u30fc\u30d0\u30fc\u304c\u5bb9\u6613\u306b\u6271\u3048\u308b\u4e8b\u306b\u559c\u3073\u3092\u611f\u3058\u3066\u304a\u308a\u307e\u3059\u3002<\/p>\n<p>\u5f15\u304d\u7d9a\u304dRust\u306e\u30b5\u30fc\u30d0\u30fc\u5468\u308a\u3082\u8ffd\u3063\u3066\u3044\u3053\u3046\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>\u3067\u306f\u3067\u306f\u3041\u3002<\/p>\n<p><!-- notionvc: 724296b6-f91e-4fdd-85b0-a301f9862867 --><\/p>\n<p><!-- notionvc: 4536fd75-b08d-4a7e-9339-b8f5e404cac9 --><\/p>\n<p><!-- notionvc: bcc82660-e2cb-4523-ba67-02f0988d4155 --><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3069\u3082\u3067\u3059\u3002 \u6628\u5e74\u3088\u308a\u696d\u52d9\u3067\u30ac\u30c3\u30c4\u30eaRust\u3067\u306e\u958b\u767a\u3092\u884c\u3063\u3066\u306f\u3044\u308b\u306e\u3067\u3059\u304c\u3001\u4e3b\u306b\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u30a2\u30d7\u30ea\u958b\u767a\u306e\u65b9\u3067\u3001\u305d\u3046\u3044\u3048\u3070\u30b5\u30fc\u30d0\u30fc\u5468\u308a\u306f\u3069\u3046\u306a\u3063\u3066\u3044\u308b\u306e\u3060\u308d\u3046\u3068\u3001\u6700\u8fd1\u306f\u3082\u3054\u3082\u3054\u6f01\u3063\u3066\u3044\u308b\u72b6\u6cc1\u3060\u3063\u305f\u308a\u3057\u307e\u3059\u3002 Rust\u306easy [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":11743,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[299],"tags":[330,329,47,327,45,328,78,118],"class_list":["post-11736","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-rust","tag-actix-web","tag-api","tag-javascript-2","tag-rust","tag-web","tag-328","tag-78","tag-118"],"_links":{"self":[{"href":"https:\/\/www.webcyou.com\/index.php?rest_route=\/wp\/v2\/posts\/11736","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.webcyou.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.webcyou.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.webcyou.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.webcyou.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=11736"}],"version-history":[{"count":1,"href":"https:\/\/www.webcyou.com\/index.php?rest_route=\/wp\/v2\/posts\/11736\/revisions"}],"predecessor-version":[{"id":11742,"href":"https:\/\/www.webcyou.com\/index.php?rest_route=\/wp\/v2\/posts\/11736\/revisions\/11742"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.webcyou.com\/index.php?rest_route=\/wp\/v2\/media\/11743"}],"wp:attachment":[{"href":"https:\/\/www.webcyou.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=11736"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webcyou.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=11736"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webcyou.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=11736"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}