{"id":13672126,"url":"https://github.com/viniciusgerevini/http-test-server","last_synced_at":"2025-04-22T18:46:51.803Z","repository":{"id":62440340,"uuid":"151846035","full_name":"viniciusgerevini/http-test-server","owner":"viniciusgerevini","description":"Programatically create resources and pre-defined responses for tests","archived":false,"fork":false,"pushed_at":"2023-04-27T01:27:45.000Z","size":73,"stargazers_count":11,"open_issues_count":2,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-13T09:47:15.432Z","etag":null,"topics":["http","mock","test"],"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/viniciusgerevini.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-10-06T14:07:47.000Z","updated_at":"2024-11-09T21:31:59.000Z","dependencies_parsed_at":"2024-11-11T10:41:42.097Z","dependency_job_id":null,"html_url":"https://github.com/viniciusgerevini/http-test-server","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/viniciusgerevini%2Fhttp-test-server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/viniciusgerevini%2Fhttp-test-server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/viniciusgerevini%2Fhttp-test-server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/viniciusgerevini%2Fhttp-test-server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/viniciusgerevini","download_url":"https://codeload.github.com/viniciusgerevini/http-test-server/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250301304,"owners_count":21408144,"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":["http","mock","test"],"created_at":"2024-08-02T09:01:27.376Z","updated_at":"2025-04-22T18:46:51.763Z","avatar_url":"https://github.com/viniciusgerevini.png","language":"Rust","funding_links":[],"categories":["Rust"],"sub_categories":[],"readme":"# HTTP Test Server\n\n[![Documentation](https://docs.rs/http-test-server/badge.svg)](https://docs.rs/http-test-server/) [![Build Status](https://github.com/viniciusgerevini/http-test-server/actions/workflows/rust.yml/badge.svg)](https://github.com/viniciusgerevini/http-test-server/actions/workflows/rust.yml)\n\nProgramatically create end-points that listen for connections and return pre-defined responses.\n\n- Allows multiple endpoints and simultaneous client connections\n- Streaming support\n- Helper functions to retrieve data such as request count, number of connected clients and\nrequests metadata\n- Automatically allocates free port and close server after use\n\n# Examples:\n\nAccept POST requests:\n```rust\nextern crate http_test_server;\n\nuse http_test_server::{TestServer, Resource};\nuse http_test_server::http::{Status, Method};\n\nlet server = TestServer::new().unwrap();\nlet resource = server.create_resource(\"/some-endpoint/new\");\n\nresource\n    .status(Status::Created)\n    .method(Method::POST)\n    .header(\"Content-Type\", \"application/json\")\n    .header(\"Cache-Control\", \"no-cache\")\n    .body(\"{ \\\"message\\\": \\\"this is a message\\\" }\");\n\n// request: POST /some-endpoint/new\n\n// HTTP/1.1 201 Created\\r\\n\n// Content-Type: application/json\\r\\n\n// Cache-Control: no-cache\\r\\n\n// \\r\\n\n// { \"message\": \"this is a message\" }\n```\n\nUse path and query parameters\n```rust\nextern crate http_test_server;\n\nuse http_test_server::{TestServer, Resource};\nuse http_test_server::http::{Status, Method};\n\nlet server = TestServer::new().unwrap();\nlet resource = server.create_resource(\"/user/{userId}?filter=*\");\n\nresource\n    .status(Status::OK)\n    .header(\"Content-Type\", \"application/json\")\n    .header(\"Cache-Control\", \"no-cache\")\n    .body(r#\"{ \"id\": \"{path.userId}\", \"filter\": \"{query.filter}\" }\"#);\n\n// request: GET /user/abc123?filter=all\n\n// HTTP/1.1 200 Ok\\r\\n\n// Content-Type: application/json\\r\\n\n// Cache-Control: no-cache\\r\\n\n// \\r\\n\n// { \"id\": \"abc123\", \"filter\": \"all\" }\n```\n\nExpose a persistent stream:\n```rust\nlet server = TestServer::new().unwrap();\nlet resource = server.create_resource(\"/sub\");\n\nresource\n    .header(\"Content-Type\", \"text/event-stream\")\n    .header(\"Cache-Control\", \"no-cache\")\n    .stream()\n    .body(\": initial data\");\n\n// ...\n\nresource\n    .send(\"some data\")\n    .send(\" some extra data\\n\")\n    .send_line(\"some extra data with line break\")\n    .close_open_connections();\n\n// request: GET /sub\n\n// HTTP/1.1 200 Ok\\r\\n\n// Content-Type: text/event-stream\\r\\n\n// Cache-Control: no-cache\\r\\n\n// \\r\\n\n// : initial data\n// some data some extra data\\n\n// some extra data with line break\\n\n```\n\nRedirects:\n```rust\nlet server = TestServer::new().unwrap();\nlet resource_redirect = server.create_resource(\"/original\");\nlet resource_target = server.create_resource(\"/new\");\n\nresource_redirect\n    .status(Status::SeeOther)\n    .header(\"Location\", \"/new\" );\n\nresource_target.body(\"Hi!\");\n\n// request: GET /original\n\n// HTTP/1.1 303 See Other\\r\\n\n// Location: /new\\r\\n\n// \\r\\n\n```\n\nRegex URI:\n\n```rust\nlet server = TestServer::new().unwrap();\nlet resource = server.create_resource(\"/hello/[0-9]/[A-z]/.*\");\n\n// request: GET /hello/8/b/doesntmatter-hehe\n\n// HTTP/1.1 200 Ok\\r\\n\n// \\r\\n\n\n```\n\nCheck  [/tests/integration_test.rs](tests/integration_test.rs) for more usage examples.\n\n---\n*NOTE*: This is not intended to work as a full featured server. For this reason, many validations\nand behaviours are not implemented. e.g: A request with `Accept` header with not supported\n`Content-Type` won't trigger a `406 Not Acceptable`.\n\nAs this crate was devised to be used in tests, smart behaviours could be confusing and misleading. Having said that, for the sake of convenience, some default behaviours were implemented:\n\n- Server returns `404 Not Found` when requested resource was not configured.\n- Server returns `405 Method Not Allowed` when trying to reach resource with different method from those configured.\n- When a resource is created it responds to `GET` with `200 Ok` by default.\n---\n\n## License\n\nLicensed under either of\n\n * Apache License, Version 2.0\n   ([LICENSE-APACHE](LICENSE-APACHE))\n * MIT license\n   ([LICENSE-MIT](LICENSE-MIT))\n\nat your option.\n\n## Contribution\n\nUnless you explicitly state otherwise, any contribution intentionally submitted\nfor inclusion in the work by you, as defined in the Apache-2.0 license, shall be\ndual licensed as above, without any additional terms or conditions.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fviniciusgerevini%2Fhttp-test-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fviniciusgerevini%2Fhttp-test-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fviniciusgerevini%2Fhttp-test-server/lists"}