#http-mocking #testing #web-api #mocking #api-mocking

bin+lib apimock

API mock Server generating HTTP/JSON responses

47 stable releases

new 3.2.0 May 10, 2025
2.9.6 May 4, 2025
2.9.4 Mar 26, 2025
2.6.5 Oct 15, 2024
2.0.4 Mar 5, 2024

#1009 in Web programming

Download history 2/week @ 2025-01-31 39/week @ 2025-02-07 396/week @ 2025-02-14 18/week @ 2025-02-21 414/week @ 2025-02-28 558/week @ 2025-03-07 480/week @ 2025-03-14 134/week @ 2025-03-21 48/week @ 2025-03-28 7/week @ 2025-04-04 10/week @ 2025-04-11 109/week @ 2025-04-25 863/week @ 2025-05-02

984 downloads per month
Used in apimokka

Apache-2.0

145KB
1.5K SLoC

apimock-rs

crates.io Documentation Dependency Status Releases Workflow License

Summary

HTTP server generating REST/JSON responses. Aims to be mocking helper to develop microservices and APIs. Written in Rust and based on hyper.

Run ./apimock or ./apimock -c apimock.toml to start the server. It is single small native binary. Multiple platforms are supported and no installation is required.

Screenshots

Server started to listen:

server starts

curl test result:

server responds

Middleware is available as rhai script:

server responds

Features

1. Basic

  • GET / POST methods
  • Multiple paths
  • Multiple .json/.json5 files treated as JSON Response
  • based on hyper v1

2. Customization

  • Custom HTTP response codes: 3xx as redirects, and 4xx and 5xx as errors
  • Custom response headers which are reusable
  • Can specify response time on all or each API path
  • Middleware as rhai script (ref: Rhai book (Statements chapter)) is available to customize request routing and response handling

3. Dynamic processing

  • Flexible responses with patterns and jsonpath queries. Even with the same API URL path, multiple responses can be returned. See url.paths_patterns
  • Dynamic path resolution with dyn_data_dir

4. Safe and observable usage

  • Validates configuration: Missing JSON files, duplicate paths etc.
  • Prints out routing at startup
  • Describes request content on both HTTP headers and body (json or plain text) when verbose log is activated

5. Test helper

6. spawn feature

  • With spawn feature activated, the server is available as subprocess. The output will be returned via tokio mpsc queue.

Reference

Acknowledgements

Depends on:

tokio / hyper / toml / serde / serde_json / json5 / console / rhai. In addition, mdbook (as to workflows)

Dependencies

~15–26MB
~373K SLoC