Quick Start

  1. Download the httpstub JAR file from the Github repository's releases page. Or download docker image from ghcr.io

  2. Create folder for stubs

    mkdir -p data
  3. Create a YAML file api-definition.yaml at data folder with the API definition.

Here's an example YAML file that defines a simple endpoint that returns a static JSON response:

#data/api-definition.yaml
rules:
  request:
    path: /hello
  response:
    body: Hello, world!

This YAML file specifies that when an HTTP GET request is received with a path of /hello, the server should respond with a 200 status code and a plain text containing the message "Hello, world!".

  1. Run the httpstub server using the following command(replacing httpstub.jar with the name of the JAR file you downloaded in step 1):

STUB_DATA=$(pwd)/data java -jar httpstub.jar

This will start the httpstub server and load the API definition from the YAML file from $(pwd)/data (folder with data from our current location).

  1. Test the httpstub server by sending an HTTP GET request to the endpoint defined in the YAML file. For example, if you're running the server on localhost port 8080, you can use a tool like curl to send the request:

curl http://localhost:8080/hello

This should return the following response:

Hello, world!s

That's it! You've successfully set up and tested an httpstub server using a YAML API definition file.

Docker

Docker image is available on ghcr.io/gleb619/httpstub

docker run -v $PWD/data:/app/data:ro -p 8080:8080 ghcr.io/gleb619/httpstub

Last updated