{"id":13425236,"url":"https://github.com/r-lib/webfakes","last_synced_at":"2025-12-12T02:27:26.624Z","repository":{"id":43867872,"uuid":"251348839","full_name":"r-lib/webfakes","owner":"r-lib","description":"Fake web apps for HTTP testing R packages","archived":false,"fork":false,"pushed_at":"2025-10-21T08:12:57.000Z","size":10787,"stargazers_count":63,"open_issues_count":9,"forks_count":6,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-12-09T01:53:16.478Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://webfakes.r-lib.org","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/r-lib.png","metadata":{"files":{"readme":"README.Rmd","changelog":"NEWS.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","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,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2020-03-30T15:34:05.000Z","updated_at":"2025-10-21T07:06:17.000Z","dependencies_parsed_at":"2023-01-21T16:01:41.563Z","dependency_job_id":"d36c4d0c-b40c-4e45-86c3-a509638a08cf","html_url":"https://github.com/r-lib/webfakes","commit_stats":{"total_commits":421,"total_committers":4,"mean_commits":105.25,"dds":"0.19477434679334915","last_synced_commit":"b072f51a982768af415b7955f47c5ef0871f7093"},"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"purl":"pkg:github/r-lib/webfakes","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/r-lib%2Fwebfakes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/r-lib%2Fwebfakes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/r-lib%2Fwebfakes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/r-lib%2Fwebfakes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/r-lib","download_url":"https://codeload.github.com/r-lib/webfakes/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/r-lib%2Fwebfakes/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":27674648,"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-12-12T02:00:06.775Z","response_time":129,"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":[],"created_at":"2024-07-31T00:01:08.027Z","updated_at":"2025-12-12T02:27:26.610Z","avatar_url":"https://github.com/r-lib.png","language":"C","readme":"---\noutput: github_document\neditor_options:\n  markdown:\n    wrap: sentence\n    canonical: true\n---\n\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\n```{r}\n#| label: setup\n#| echo: false\n#| message: false\nknitr::opts_chunk$set(\n  comment = \"#\u003e\",\n  tidy = FALSE,\n  error = FALSE,\n  fig.width = 8,\n  fig.height = 8)\n```\n\n# webfakes\n\n\u003e Your own web server for happy HTTP testing\n\n\u003c!-- badges: start --\u003e\n\n[![R build status](https://github.com/r-lib/webfakes/workflows/R-CMD-check/badge.svg)](https://github.com/r-lib/webfakes/actions)\n[![CRAN status](https://www.r-pkg.org/badges/version/webfakes)](https://CRAN.R-project.org/package=webfakes)\n[![R-CMD-check](https://github.com/r-lib/webfakes/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/r-lib/webfakes/actions/workflows/R-CMD-check.yaml)\n[![Codecov test coverage](https://codecov.io/gh/r-lib/webfakes/graph/badge.svg)](https://app.codecov.io/gh/r-lib/webfakes)\n\u003c!-- badges: end --\u003e\n\nLightweight fake web apps for testing.\nBuilt using the [civetweb](https://github.com/civetweb/civetweb) embedded web server.\n\n## Features\n\n-   Complete web app framework, define handlers for HTTP requests in R.\n-   Write your own app for your custom test cases; our use app similar to the `https://httpbin.org` API, so often you don't need to write your own web app (e.g. if you are writing an HTTP client (httr, curl, crul).\n-   Run one web app per test suite, per test file or per test case.\n-   Flexible path matching, with parameters and regular expressions.\n-   Built in templating system using glue or bring your own template engine.\n-   Middleware to parse JSON, multipart and URL encoded request bodies.\n-   A web app is just an R object. It can be saved to disk, copied to another R process, etc.\n-   A web app is extensible, by adding new routes and middleware to it.\n-   Helper functions for sending JSON, files from disk, etc.\n-   App-specific environment to store any data including data from requests to the fake app.\n-   After a web app is launched from R, you can interact with it from R but also from the command line, your browser, etc. Nice for debugging.\n-   The web server runs in the R process, so it has no problems with local firewalls.\n-   Multi-threaded web server supports concurrent HTTP requests.\n-   Limit download speed to simulate low bandwidth.\n\n## Optional dependencies\n\n-   The jsonlite package is needed for the `mw_json()` middleware, the `response$send_json()` method and the `httpbin_app()` app.\n-   The glue package is needed for the `tmpl_glue()` template engine.\n-   The callr package is needed for `new_app_process()` and `local_app_process` to work.\n-   The `/brotli` endpoint of `httpbin_app()` needs the brotli package.\n-   The `/deflate` endpoint of `httpbin_app()` needs the zip package.\n-   The `/digest-auth` endpoint of `httpbin_app()` needs the digest package.\n-   `git_app()` requires the processx package.\n\n## Installation\n\nInstall the release version from CRAN:\n\n``` r\ninstall.packages(\"webfakes\")\n```\n\nIf you need the development version of the package, install it from GitHub:\n\n``` r\npak::pak(\"r-lib/webfakes\")\n```\n\n## Usage\n\nStart a web app at the beginning of your tests or test file, and stop it after.\nHere is an example with the testthat package.\nSuppose you want to test that your `get_hello()` function can query an API:\n\n```{r}\n#| include: false\nlibrary(testthat)\n```\n\n`local_app_process()` helps you clean up the web server process after the test block, or test file.\nIt is similar to the `withr::local_*` functions.\n\n``` r\napp \u003c- webfakes::new_app()\napp$get(\"/hello/:user\", function(req, res) {\n  res$send(paste0(\"Hello \", req$params$user, \"!\"))\n})\nweb \u003c- webfakes::local_app_process(app)\n\ntest_that(\"can use hello API\", {\n  url \u003c- web$url(\"/hello/Gabor\")\n  expect_equal(get_hello(url), \"Hello Gabor!\")\n})\n```\n\nWhen testing HTTP clients you can often use the built in `httpbin_app()`:\n\n```{r}\n#| eval: false\nhttpbin \u003c- webfakes::local_app_process(webfakes::httpbin_app())\n```\n\n```{r}\n#| include: false\nsuppressMessages(\n  httpbin \u003c- webfakes::local_app_process(webfakes::httpbin_app())\n)\n```\n\n```{r}\ntest_that(\"HTTP errors are caught\", {\n  url \u003c- httpbin$url(\"/status/404\")\n  resp \u003c- httr::GET(url)\n  expect_error(httr::stop_for_status(resp), class = \"http_404\")\n})\n```\n\n## Documentation\n\nSee \u003chttps://webfakes.r-lib.org\u003e\n\n## Links\n\n### Other solutions for HTTP testing in R:\n\n-   [vcr](https://github.com/ropensci/vcr)\n-   [httptest](https://github.com/nealrichardson/httptest)\n\n### R web application frameworks\n\nwebfakes focuses on testing, these packages are for writing real web apps:\n\n-   [shiny](https://github.com/rstudio/shiny)\n-   [opencpu](https://www.opencpu.org/)\n-   [plumber](https://github.com/rstudio/plumber)\n-   [fiery](https://github.com/thomasp85/fiery)\n-   [RestRserve](https://github.com/rexyai/RestRserve)\n\n## Code of Conduct\n\nPlease note that the webfakes project is released with a\n[Contributor Code of Conduct](https://webfakes.r-lib.org/dev/CODE_OF_CONDUCT.html).\nBy contributing to this project, you agree to abide by its terms.\n\n## License\n\nMIT © RStudio\n","funding_links":[],"categories":["HTML"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fr-lib%2Fwebfakes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fr-lib%2Fwebfakes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fr-lib%2Fwebfakes/lists"}