{"id":22089826,"url":"https://github.com/speakeasy-api/speakeasy-rust-sdk","last_synced_at":"2025-08-16T05:33:59.593Z","repository":{"id":59184649,"uuid":"535841805","full_name":"speakeasy-api/speakeasy-rust-sdk","owner":"speakeasy-api","description":"Speakeasy Serverside SDK for Rust REST APIs","archived":false,"fork":false,"pushed_at":"2023-02-16T15:35:39.000Z","size":306,"stargazers_count":4,"open_issues_count":1,"forks_count":4,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-08-08T20:18:43.526Z","etag":null,"topics":["actix","actix-web","actix-web-middleware","api-ops","axum","axum-server","devportal","har","request-logs","rest","rest-api","rust","schema-generation"],"latest_commit_sha":null,"homepage":"https://www.speakeasyapi.dev/","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/speakeasy-api.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-09-12T20:36:12.000Z","updated_at":"2023-07-26T10:05:28.000Z","dependencies_parsed_at":"2023-01-22T20:30:08.955Z","dependency_job_id":null,"html_url":"https://github.com/speakeasy-api/speakeasy-rust-sdk","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/speakeasy-api/speakeasy-rust-sdk","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/speakeasy-api%2Fspeakeasy-rust-sdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/speakeasy-api%2Fspeakeasy-rust-sdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/speakeasy-api%2Fspeakeasy-rust-sdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/speakeasy-api%2Fspeakeasy-rust-sdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/speakeasy-api","download_url":"https://codeload.github.com/speakeasy-api/speakeasy-rust-sdk/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/speakeasy-api%2Fspeakeasy-rust-sdk/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270236088,"owners_count":24550191,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-13T02:00:09.904Z","response_time":66,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["actix","actix-web","actix-web-middleware","api-ops","axum","axum-server","devportal","har","request-logs","rest","rest-api","rust","schema-generation"],"created_at":"2024-12-01T02:14:24.157Z","updated_at":"2025-08-16T05:33:59.568Z","avatar_url":"https://github.com/speakeasy-api.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# speakeasy-rust-sdk\n\n![180100416-b66263e6-1607-4465-b45d-0e298a67c397](https://user-images.githubusercontent.com/68016351/181640742-31ab234a-3b39-432e-b899-21037596b360.png)\n\nSpeakeasy is your API Platform team as a service. Use our drop in SDK to manage all your API Operations including embeds for request logs and usage dashboards, test case generation from traffic, and understanding API drift.\n\nThe Speakeasy Rust SDK for evaluating API requests/responses. Currently compatible with axum and actix.\n\n## Requirements\n\nSupported Frameworks:\n\n- Axum\n- Actix 4\n- Actix 3\n\n## Usage\n\nAvailable on crates: [crates.io/crates/speakeasy-rust-sdk](https://crates.io/crates/speakeasy-rust-sdk)\n\nDocumentation available at: [docs.rs/speakeasy-rust-sdk](https://docs.rs/speakeasy-rust-sdk)\n\nRun:\n\n```\ncargo add speakeasy-rust-sdk --features actix4\n```\n\nOr add it directly to your `Cargo.toml`\n\n```toml\nspeakeasy-rust-sdk = {version = \"0.3.0\", features = [\"actix4\"]}\n```\n\n### Minimum configuration\n\n[Sign up for free on our platform](https://www.speakeasyapi.dev/). After you've created a workspace and generated an API key enable Speakeasy in your API as follows:\n\n_(for axum configuration see the example at [examples/axum/](examples/axum/src/main.rs))_\n\nConfigure Speakeasy at the start of your `main()` function:\n\n```rust\nuse actix_web::{\n    get, post,\n    web::{self, ReqData},\n    App, HttpResponse, HttpServer, Responder,\n};\nuse speakeasy_rust_sdk::{middleware::actix3::Middleware, Config, SpeakeasySdk};\n\n#[actix_web::main]\nasync fn main() -\u003e std::io::Result\u003c()\u003e {\n   HttpServer::new(|| {\n        let config = Config {\n            // retrieve from Speakeasy API dashboard.\n            api_key: \"YOUR API KEY HERE\".to_string(),\n            // enter a name that you'd like to associate captured requests with.\n            // This name will show up in the Speakeasy dashboard. e.g. \"PetStore\" might be a good ApiID for a Pet Store's API.\n            // No spaces allowed.\n            api_id: \"YOUR API ID HERE\".to_string(),\n            // enter a version that you would like to associate captured requests with.\n            // The combination of ApiID (name) and VersionID will uniquely identify your requests in the Speakeasy Dashboard.\n            // e.g. \"v1.0.0\". You can have multiple versions for the same ApiID (if running multiple versions of your API)\n            version_id: \"YOUR VERSION ID HERE\".to_string(),\n        };\n\n        // Create a new Speakeasy SDK instance\n        let mut sdk = SpeakeasySdk::try_new(config).expect(\"API key is valid\");\n\n        // create middleware\n        let speakeasy_middleware = Middleware::new(sdk);\n        let (request_capture, response_capture) = speakeasy_middleware.into();\n\n        App::new()\n            .wrap(request_capture)\n            .wrap(response_capture)\n            ...\n    })\n    .bind((\"127.0.0.1\", 8080))?\n    .run()\n    .await\n}\n```\n\nBuild and deploy your app and that's it. Your API is being tracked in the Speakeasy workspace you just created\nand will be visible on the dashboard next time you log in. Visit our [docs site](https://docs.speakeasyapi.dev/) to\nlearn more.\n\n### On-Premise Configuration\n\nThe SDK provides a way to redirect the requests it captures to an on-premise deployment of the Speakeasy Platform. This is done through the use of environment variables listed below. These are to be set in the environment of your services that have integrated the SDK:\n\n- `SPEAKEASY_SERVER_URL` - The url of the on-premise Speakeasy Platform's GRPC Endpoint. By default this is `grpc.prod.speakeasyapi.dev:443`.\n- `SPEAKEASY_SERVER_SECURE` - Whether or not to use TLS for the on-premise Speakeasy Platform. By default this is `true` set to `SPEAKEASY_SERVER_SECURE=\"false\"` if you are using an insecure connection.\n\n## Request Matching\n\nThe Speakeasy SDK out of the box will do its best to match requests to your provided OpenAPI Schema. It does this by extracting the path template used by one of the supported routers or frameworks above for each request captured and attempting to match it to the paths defined in the OpenAPI Schema, for example:\n\n```rust\n// The path template \"/v1/users/{id}\" is captured automatically by the SDK\n#[get(\"v1/users/{id}\")]\nasync fn handler_function(id: web::Path\u003cString\u003e) -\u003e impl Responder {\n    // handler function code\n}\n```\n\nThis isn't always successful or even possible, meaning requests received by Speakeasy will be marked as `unmatched`, and potentially not associated with your Api, Version or ApiEndpoints in the Speakeasy Dashboard.\n\nTo help the SDK in these situations you can provide path hints per request handler that match the paths in your OpenAPI Schema:\n\n```rust\n#[post(\"/special_route\")]\nasync fn special_route(controller: ReqData\u003cArc\u003cRwLock\u003cMiddlewareController\u003e\u003e\u003e) -\u003e HttpResponse {\n    // Provide a path hint for the request using the OpenAPI Path templating format:\n    //  https://swagger.io/specification/#path-templating-matching\n    controller\n        .write()\n        .unwrap()\n        .set_path_hint(\"/special_route/{wildcard}\");\n\n\t// the rest of your handlers code\n}\n```\n\n## Capturing Customer IDs\n\nTo help associate requests with customers/users of your APIs you can provide a customer ID per request handler:\n\n```rust\n#[post(\"/index\")]\nasync fn index(controller: ReqData\u003cArc\u003cRwLock\u003cMiddlewareController\u003e\u003e\u003e) -\u003e HttpResponse {\n    controller\n        .write()\n        .unwrap()\n        .set_customer_id(\"123customer_id\".to_string());\n\n    // rest of the handlers code\n}\n\n```\n\nNote: This is not required, but is highly recommended. By setting a customer ID you can easily associate requests with your customers/users in the Speakeasy Dashboard, powering filters in the [Request Viewer](https://docs.speakeasyapi.dev/speakeasy-user-guide/request-viewer).\n\n## Masking sensitive data\n\nSpeakeasy can mask sensitive data in the query string parameters, headers, cookies and request/response bodies captured by the SDK. This is useful for maintaining sensitive data isolation, and retaining control over the data that is captured.\n\nYou can set masking options globally, this options will be applied to all requests and response.\n\n```rust\n#[actix_web::main]\nasync fn main() -\u003e std::io::Result\u003c()\u003e {\n   HttpServer::new(|| {\n        let config = Config {\n            // retrieve from Speakeasy API dashboard.\n            api_key: \"YOUR API KEY HERE\".to_string(),\n            // enter a name that you'd like to associate captured requests with.\n            // This name will show up in the Speakeasy dashboard. e.g. \"PetStore\" might be a good ApiID for a Pet Store's API.\n            // No spaces allowed.\n            api_id: \"YOUR API ID HERE\".to_string(),\n            // enter a version that you would like to associate captured requests with.\n            // The combination of ApiID (name) and VersionID will uniquely identify your requests in the Speakeasy Dashboard.\n            // e.g. \"v1.0.0\". You can have multiple versions for the same ApiID (if running multiple versions of your API)\n            version_id: \"YOUR VERSION ID HERE\".to_string(),\n        };\n\n        // Create a new Speakeasy SDK instance\n        let mut sdk = SpeakeasySdk::try_new(config).expect(\"API key is valid\");\n\n        // Configure masking for query\n        sdk.masking().with_query_string_mask(\"secret\", \"********\");\n        sdk.masking()\n            .with_query_string_mask(\"password\", StringMaskingOption::default());\n\n        // Configure masking for request\n        sdk.masking()\n            .with_request_field_mask_string(\"password\", StringMaskingOption::default());\n\n        // Configure masking for **response**\n        sdk.masking()\n            .with_response_field_mask_string(\"secret\", StringMaskingOption::default());\n\n        // create middleware\n        let speakeasy_middleware = Middleware::new(sdk);\n        let (request_capture, response_capture) = speakeasy_middleware.into();\n\n        App::new()\n            .wrap(request_capture)\n            .wrap(response_capture)\n            ...\n    })\n    .bind((\"127.0.0.1\", 8080))?\n    .run()\n    .await\n}\n```\n\nBut if you would like to be more selective you can mask certain sensitive data using our middleware controller allowing you to mask fields as needed in different handlers:\n\n```rust\nuse speakeasy_rust_sdk::{Masking, MiddlewareController, SpeakeasySdk, StringMaskingOption};\n\n#[post(\"/index\")]\nasync fn index(controller: ReqData\u003cArc\u003cRwLock\u003cMiddlewareController\u003e\u003e\u003e) -\u003e HttpResponse {\n    // create a specific masking for this request/response\n    let mut masking = Masking::default();\n    masking.with_request_field_mask_string(\"password\", StringMaskingOption::default());\n\n    // set new masking for this request/response\n    controller.write().unwrap().set_masking(masking);\n\n    // rest of the handlers code\n}\n```\n\nThe `Masking` struct can be set with a number of different options to mask sensitive data in the request:\n\n- `masking.with_query_string_mask` - **with_query_string_mask** will mask the specified query strings with an optional mask string.\n- `masking.with_request_header_mask` - **with_request_header_mask** will mask the specified request headers with an optional mask string.\n- `masking.with_response_header_mask` - **with_response_header_mask** will mask the specified response headers with an optional mask string.\n- `masking.with_request_cookie_mask` - **with_request_cookie_mask** will mask the specified request cookies with an optional mask string.\n- `masking.with_response_cookie_mask` - **with_response_cookie_mask** will mask the specified response cookies with an optional mask string.\n- `masking.with_request_field_mask_string` - **with_request_field_mask_string** will mask the specified request body fields with an optional mask. Supports string fields only. Matches using regex.\n- `masking.with_request_field_mask_number` - **with_request_field_mask_number** will mask the specified request body fields with an optional mask. Supports number fields only. Matches using regex.\n- `masking.with_response_field_mask_string` - **with_response_field_mask_string** will mask the specified response body fields with an optional mask. Supports string fields only. Matches using regex.\n- `masking.with_response_field_mask_number` - **with_response_field_mask_number** will mask the specified response body fields with an optional mask. Supports number fields only. Matches using regex.\n\nFor complete docs on masking see the [docs.rs/speakeasy-rust-sdk](https://docs.rs/speakeasy-rust-sdk/latest/speakeasy_rust_sdk/)\n\n### Embedded Request Viewer Access Tokens\n\nThe Speakeasy SDK can generate access tokens for the [Embedded Request Viewer](https://docs.speakeasyapi.dev/docs/using-speakeasy/build-dev-portals/intro/index.html) that can be used to view requests captured by the SDK.\n\nFor documentation on how to configure filters, find that [HERE](https://docs.speakeasyapi.dev/docs/using-speakeasy/build-dev-portals/intro/index.html).\n\nBelow are some examples on how to generate access tokens:\n\n```rust\nuse speakeasy_rust_sdk::speakeasy_protos::embedaccesstoken::{\n    embed_access_token_request::Filter, EmbedAccessTokenRequest,\n};\n\nlet request = EmbedAccessTokenRequest {\n    filters: vec![Filter {\n        key: \"customer_id\".to_string(),\n        operator: \"=\".to_string(),\n        value: \"a_customer_id\".to_string(),\n    }],\n    ..Default::default()\n};\n\nlet token_response = app_state\n    .speakeasy_sdk\n    .get_embedded_access_token(request)\n    .await\n    .unwrap();\n```\n\n### Examples\n\n- Axum - [examples/axum/](examples/axum/)\n- Actix4 - [examples/actix4/](examples/actix4/)\n- Actix3 - [examples/actix3/](examples/actix3/)\n- Actix3 Test Server - [testserver/](testserver/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspeakeasy-api%2Fspeakeasy-rust-sdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspeakeasy-api%2Fspeakeasy-rust-sdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspeakeasy-api%2Fspeakeasy-rust-sdk/lists"}