Skip to content

vncsmyrnk/fakeapi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

143 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CI workflow Release workflow contributions Issue count
CLI version Docker Image Version LuaRocks

Fake API

CLI for dummy REST API testing other software.

Fake API allows you to quickly set up and run a RESTful API server with customizable endpoints and responses. This makes it an ideal tool for developers who need a reliable and easy-to-use mock server for testing their software without relying on external services.

Examples

You are building a client interface for an app that does not yet have its backend services properly set up. You only have a contract of what the backend will be in the future. How can you mock this API in a way that behaves as closely as possible to the real one? Fake API was designed to address this issue.

It is useful not only for building frontend interfaces but also whenever you need to mock a REST service with customizable controls.

cat <<EOF > server-config.json
[
  {
    "path": "/my-route",
    "method": "POST",
    "statusCode": 200,
    "response": {
      "name": "value",
      "other-name": {
        "some-other-name": "another-value"
      }
    }
  }
]
EOF
fakeapi-server --port 8080 server-config.json
curl -X POST localhost:8080/my-route
# {"name":"value","other-name":{"some-other-name":"another-value"}}

Assertions

All requests sent to the fake API are stored locally and can be queried later for assertions. This is useful for verifying that the expected requests were made to the API during automated tests.

The assert CLI checks whether a specific request was received by the server. It returns a zero exit code on success and a non-zero exit code on failure.

fakeapi assert --port 8080 POST /my-route
# Exit code 0: a POST request to /my-route was received
# Exit code 1: no matching request was found

You can also filter for body attributes, headers and query strings using GJSON Path Syntax.

Install

Server

nix profile add github:vncsmyrnk/fakeapi#fakeapi-server
docker run --rm -it -p 8080:8080 vncsmyrnk/fakeapi

CLI

nix profile add github:vncsmyrnk/fakeapi

APIs

Wrappers for fakeapi in other languages/tools.

Lua

luarocks install fakeapi --local --lua-version=5.1

Roadmap and new features

Check the milestones section to see what is currently being planned or in development.

About

Customizable local REST API for testing.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors