{"id":21659793,"url":"https://github.com/oxidecomputer/dropshot","last_synced_at":"2025-07-17T22:33:08.278Z","repository":{"id":36976654,"uuid":"273549074","full_name":"oxidecomputer/dropshot","owner":"oxidecomputer","description":"expose REST APIs from a Rust program","archived":false,"fork":false,"pushed_at":"2025-07-08T18:36:59.000Z","size":3471,"stargazers_count":1068,"open_issues_count":74,"forks_count":84,"subscribers_count":31,"default_branch":"main","last_synced_at":"2025-07-08T19:47:05.789Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/oxidecomputer.png","metadata":{"files":{"readme":"README.adoc","changelog":"CHANGELOG.adoc","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2020-06-19T17:18:17.000Z","updated_at":"2025-07-08T01:11:03.000Z","dependencies_parsed_at":"2024-01-25T20:24:26.207Z","dependency_job_id":"2c3df58f-1a3c-4968-9f41-6392c11a50fc","html_url":"https://github.com/oxidecomputer/dropshot","commit_stats":{"total_commits":554,"total_committers":32,"mean_commits":17.3125,"dds":"0.45848375451263534","last_synced_commit":"d17f74d428f0adf7fcab09663c708c72c34b99c0"},"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"purl":"pkg:github/oxidecomputer/dropshot","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oxidecomputer%2Fdropshot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oxidecomputer%2Fdropshot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oxidecomputer%2Fdropshot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oxidecomputer%2Fdropshot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/oxidecomputer","download_url":"https://codeload.github.com/oxidecomputer/dropshot/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oxidecomputer%2Fdropshot/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265672343,"owners_count":23808844,"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","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":[],"created_at":"2024-11-25T09:31:34.726Z","updated_at":"2025-07-17T22:33:07.702Z","avatar_url":"https://github.com/oxidecomputer.png","language":"Rust","funding_links":[],"categories":["Rust"],"sub_categories":[],"readme":":showtitle:\n:toc: left\n:icons: font\n\n= Dropshot\n\nimage::https://github.com/oxidecomputer/dropshot/workflows/Rust/badge.svg[]\n\nDropshot is a general-purpose crate for exposing REST APIs from a Rust program.\nFor more, see the https://docs.rs/dropshot/[online Dropshot documentation].\nYou can build the documentation yourself with:\n\n[source,text]\n----\n$ cargo +nightly doc\n----\n\n== Contributing\n\nYou can **build and run the whole test suite** with `cargo test`.  The test\nsuite runs cleanly and should remain clean.\n\nYou can format the code using `cargo fmt`.  CI checks that code is correctly formatted.\n\nhttps://github.com/rust-lang/rust-clippy[Clippy] is used to check for common code issues.  (We disable most style checks; see the `[workspace.lints.clippy]` section in `Cargo.toml` for the full configuration.)  You can run it with `cargo clippy --all-targets -- --deny warnings`.  CI will run clippy as well.\n\nFor maintainers (e.g., publishing new releases and managing dependabot), see link:./MAINTAINERS.adoc[MAINTAINERS.adoc].\n\n== Configuration reference\n\n=== Dropshot servers\n\nDropshot servers use a TOML configuration file.  Supported config properties\ninclude:\n\n[cols=\"1,1,1,3\",options=\"header\"]\n|===\n|Name\n|Example\n|Required?\n|Description\n\n|`bind_address`\n|`\"127.0.0.1:12220\"`\n|No\n|Specifies that the server should bind to the given IP address and TCP port.  In general, servers can bind to more than one IP address and port, but this is not (yet?) supported. Defaults to \"127.0.0.1:0\".\n\n|`default_request_body_max_bytes`\n|`4096`\n|No\n|Specifies the maximum number of bytes allowed in a request body. Larger requests will receive a 400 error. Defaults to 1024.\n\nCan be overridden per-endpoint via the `request_body_max_bytes` parameter to `#[endpoint { ... }]`.\n\n|`tls.type`\n|`\"AsFile\"`\n|No\n|Specifies if and how TLS certificate and key information is provided.  Valid values include \"AsFile\" and \"AsBytes\".\n\n|`tls.cert_file`\n|`\"/path/to/cert.pem\"`\n|Only if `tls.type = AsFile`\n|Specifies the path to a PEM file containing a certificate chain for the server to identify itself with. The first certificate is the end-entity certificate, and the remaining are intermediate certificates on the way to a trusted CA. If specified, the server will only listen for TLS connections.\n\n|`tls.key_file`\n|`\"/path/to/key.pem\"`\n|Only if `tls.type = AsFile`\n|Specifies the path to a PEM-encoded PKCS #8 file containing the private key the server will use. If specified, the server will only listen for TLS connections.\n\n|`tls.certs`\n|`Vec\u003cu8\u003e of certificate data`\n|Only if `tls.type = AsBytes`\n|Identical to `tls.cert_file`, but provided as a buffer.\n\n|`tls.key`\n|`Vec\u003cu8\u003e of key data`\n|Only if `tls.type = AsBytes`\n|Identical to `tls.key_file`, but provided as a buffer.\n|===\n\n=== Logging\n\nDropshot provides a small wrapper to configure a slog-based Logger.  You can use\nthis without using the rest of Dropshot.  Logging config properties include:\n\n[cols=\"1,1,1,3\",options=\"header\"]\n|===\n|Name\n|Example\n|Required?\n|Description\n\n|`mode`\n|`\"file\"`\n|Yes\n|Controls where server logging will go.  Valid modes are `\"stderr-terminal\"` and\n`\"file\".  If the mode is `\"stderr-terminal\"`, human-readable output, with colors\nand other terminal formatting if possible, will be sent to stderr.  If the mode\nis `\"file\"`, Bunyan-format output will be sent to the filesystem path given by\n`log.path`.  See also `log.if_exists`, which controls the behavior if the\ndestination path already exists.\n\n|`level`\n|`\"info\"`\n|Yes\n|Specifies what severity of log messages should be included in the log.  Valid\nvalues include `\"trace\"`, `\"debug\"`, `\"info\"`, `\"warn\"`, `\"error\"`, and\n`\"critical\"`, which are increasing order of severity.  Log messages at the\nspecified level and more severe levels will be included in the log.\n\n|`path`\n|`\"logs/server.log\"`\n|Only if `log.mode = \"file\"`\n|If `log.mode` is `\"file\"`, this property determines the path to the log file.\nSee also `log.if_exists`.\n\n|`if_exists`\n|`\"append\"`\n|Only if `log.mode = \"file\"`\n|If `log.mode` is `\"file\"`, this property specifies what to do if the\ndestination log file already exists.  Valid values include `\"append\"` (which\nappends to the existing file), `\"truncate\"` (which truncates the existing file\nand then uses it as though it had just been created), and `\"fail\"` (which causes\nthe server to exit immediately with an error).\n\n|===\n\n== Design notes\n\n=== Why is there no way to add an API handler function that runs on every request?\n\nIn designing Dropshot, we've tried to avoid a few problems we found with frameworks we used in the past.  Many (most?) web frameworks, whether in Rust or another language, let you specify a chain of handlers for each route.  You can usually specify some handlers that run before or after every request, regardless of the route.  We found that after years of evolving a complex API server using this approach, it can get quite hard to follow the control flow for a particular request and to understand the implicit dependencies between different handlers within the chain.  This made it time-consuming and error-prone to work on these API servers.  (For more details, see https://github.com/oxidecomputer/dropshot/issues/58#issuecomment-713175039[the discussion in issue 58].)\n\nWith Dropshot, we wanted to try something different: if the primary purpose of these handlers is to share code between handlers, what if we rely instead on existing mechanisms -- i.e., function calls.  The big risk is that it's easy for someone to accidentally forget some important function call, like the one that authenticates or authorizes a user.  We haven't gotten far enough in a complex implementation to need this yet, but the plan is to create a pattern of utility functions that return typed values.  For example, where in Node.js you might add an early authentication handler that fills in `request.auth`, with Dropshot you'd have an authentication function that _returns_ an `AuthzContext` struct.  Then anything that needs authentication consumes the `AuthzContext` as a function argument.  As an author of a handler, you know if you've got an `AuthzContext` available and, if not, how to get one (call the utility function).  This composes, too: you can have an authorization function that returns an `AuthnContext`, and the utility function that returns one can consume the `AuthzContext`.  Then anything that requires authorization can consume just the `AuthnContext`, and you know it's been authenticated and authorized (possibly with details in that structure).\n\nIt's early, and we may find we need richer facilities in the framework.  But we're hopeful this approach will make it faster and smoother to iterate on complex API servers.  If you pick up Dropshot and try this out, let us know how it goes!\n\n== Examples\n\nTo run the examples in dropshot/examples, clone the repository and run `cargo run --example [example_name]`, e.g. `cargo run --example basic`. (Do not include the file extension.)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foxidecomputer%2Fdropshot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foxidecomputer%2Fdropshot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foxidecomputer%2Fdropshot/lists"}