{"id":17124894,"url":"https://github.com/hobofan/dredd-hooks-rust","last_synced_at":"2025-10-16T21:33:24.503Z","repository":{"id":57621752,"uuid":"98810315","full_name":"hobofan/dredd-hooks-rust","owner":"hobofan","description":"Dredd HTTP API testing integration for Rust","archived":false,"fork":false,"pushed_at":"2017-08-10T15:51:15.000Z","size":41,"stargazers_count":7,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-13T06:11:41.183Z","etag":null,"topics":["dredd","dredd-hooks","rust","testing"],"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/hobofan.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-07-30T16:28:59.000Z","updated_at":"2020-01-29T08:30:12.000Z","dependencies_parsed_at":"2022-08-26T23:42:01.254Z","dependency_job_id":null,"html_url":"https://github.com/hobofan/dredd-hooks-rust","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hobofan%2Fdredd-hooks-rust","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hobofan%2Fdredd-hooks-rust/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hobofan%2Fdredd-hooks-rust/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hobofan%2Fdredd-hooks-rust/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hobofan","download_url":"https://codeload.github.com/hobofan/dredd-hooks-rust/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248670436,"owners_count":21142904,"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":["dredd","dredd-hooks","rust","testing"],"created_at":"2024-10-14T18:43:39.181Z","updated_at":"2025-10-16T21:33:19.457Z","avatar_url":"https://github.com/hobofan.png","language":"Rust","readme":"# dredd-hooks-rust • Dredd HTTP API testing integration for Rust\n[![Build Status](https://travis-ci.org/hobofan/dredd-hooks-rust.svg?branch=master)](https://travis-ci.org/hobofan/dredd-hooks-rust)\n[![Crates.io](https://img.shields.io/crates/v/dredd-hooks.svg)](https://crates.io/crates/dredd-hooks)\n[![docs.rs](https://docs.rs/dredd-hooks/badge.svg)](https://docs.rs/dredd-hooks)\n[![License](https://img.shields.io/badge/license-MIT%20OR%20Apache--2.0-blue.svg)]()\n\nThis package contains a Rust Dredd hook handler which provides a bridge between the [Dredd API Testing Framework](http://dredd.readthedocs.org/en/latest/)\n and Rust environment to ease implementation of testing hooks provided by [Dredd](http://dredd.readthedocs.org/en/latest/). Write Dredd hooks in Rust to glue together [API Blueprint](https://apiblueprint.org/) with your Rust project.\n\nNot sure what these Dredd Hooks are?  Read the Dredd documentation on [them](http://dredd.readthedocs.org/en/latest/hooks/).\n\nThe following are a few examples of what hooks can be used for:\n\n- loading db fixtures\n- cleanup after test step or steps\n- handling authentication and sessions\n- passing data between transactions (saving state from responses to stash)\n- modifying request generated from blueprint\n- changing generated expectations\n- setting custom expectations\n- debugging via logging stuff\n\n## Installation\n\n### Global installation\n\nIf you don't have it already, install the Dredd CLI via [npm](npm):\n\n```bash\nnpm install -g dredd\n```\n\nIn order for the Dredd CLI to be able to interface with your test binaries, you need to have the `dredd-hooks-rust` binary installed, which you can get by running:\n\n```bash\n# This will install both `dredd-hooks-rust` and `cargo-dredd`\ncargo install dredd-hooks\n```\n\n[npm]: https://docs.npmjs.com/getting-started/what-is-npm\n\n### Per-project setup\n\nTo start testing your Rust project with Dredd, just add `dredd-hooks` to your `Cargo.toml`:\n\n```toml\n[dependencies]\ndredd-hooks = \"0.3.0\"\n```\n\nOr if you have [cargo-edit][cargo-edit] installed you can just run this on the command line:\n```bash\ncargo add dredd-hooks\n```\n\n[cargo-edit]: https://github.com/killercup/cargo-edit\n\n## Quickstart example\n\nFollowing this is a short example showcasing Dredd tests running against an `iron` server.\n\nThe name of the project in this example is assumed to be `dredd-rust-test`:\n\n`test.apib`\n```apib\n# My Api\n## GET /message\n+ Response 200 (text/plain)\n    Hello World!\n```\n\n`main.rs`:\n```rust\nextern crate iron;\nextern crate router;\nextern crate dredd_hooks;\n\nuse iron::prelude::*;\nuse router::Router;\nuse dredd_hooks::{HooksServer};\n\n// HTTP endpoint\nfn endpoint(_: \u0026mut Request) -\u003e IronResult\u003cResponse\u003e {\n    Ok(Response::with((iron::status::Ok, \"Hello World!\\n\\n\")))\n}\n\nfn main() {\n    let mut hooks = HooksServer::new();\n    // Start the server before any of the tests are running.\n    hooks.before_all(Box::new(|tr| {\n        ::std::thread::spawn(move || {\n            let mut router = Router::new();\n            router.get(\"/message\", endpoint, \"endpoint\");\n\n            Iron::new(router).http(\"127.0.0.1:3000\").unwrap();\n        });\n        tr\n    }));\n    // Execute a hook before a specific test.\n    hooks.before(\"/message \u003e GET\", Box::new(|mut tr| {\n        // Set the skip flag on this test.\n        // Comment out the next line and you should see a passing test.\n        tr.insert(\"skip\".to_owned(), true.into());\n\n        tr\n    }));\n    HooksServer::start_from_env(hooks);\n}\n```\n\nRun the command:\n```bash\ncargo build \u0026\u0026 dredd ./test.apib http://127.0.0.1:3000 --language=dredd-hooks-rust --hookfiles=target/debug/dredd-rust-test\n```\n\nYou should now see Dredd trying to run the tests against the binary that was just compiled, but actually skipping the single test it tries to run because we told Dredd to do so via a `before` hook.\n\n## Project setup\n\nThe quickstart example above assumes that the hookfile is compiled as a `bin` target.\nHowever, in most projects, you will probably want to have a more robust setup that looks like this:\n\n`Cargo.toml`:\n\n```toml\n[[test]]\nname = \"dredd_test_hooks\"\npath = \"tests/dredd/hooks.rs\"\ntest = false\nharness = false\n\n[package.metadata.dredd_hooks]\nhook_targets = [\"dredd_test_hooks\"]\n```\n\nSetting the `test` value to `false`, is needed so that our blocking hookserver doesn't interfere with the other tests when running `cargo test`.\nSetting the `harness` to `false` will result in the test binary being compiled without a test harness, because we already have `dredd` as our test harness.\n\nFinally the values under `package.metadata.dredd_hooks` give us some additional metadata about our test setup, which allows us to use the `cargo dredd` command to simplify the invocation:\n```\ncargo dredd ./test.apib http://127.0.0.1:3000\n```\n\n## License\n\nLicensed under either of\n\n * Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)\n * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)\n\nat your option.\n\n## Acknowledgements\n\nThank you to:\n- [The developers behind goodman](https://github.com/snikch/goodman) for providing a good example of how to integrate Dredd with a compiled language.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhobofan%2Fdredd-hooks-rust","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhobofan%2Fdredd-hooks-rust","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhobofan%2Fdredd-hooks-rust/lists"}