DavyJ0nes / stubby

HTTP server that returns stubbed responses

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Stubby

Go Report Card Build Status Docker Info

Logo

Description

Return stubbed HTTP responses defined in a config file

Usage

Configuration

Basic

Add the routes and the responses that you want in the config file.

A basic route definition would look like:

routes:
  - path: /foo
    status: 200
    response: >-
      {
        "id": 123,
        "message": "foo"
      }

URL Query Parameters

If the response has URL parameters then these need to be defined as follows:

routes:
  - path: /foo
    queries:
      - show_deleted # this is the param key
      - true         # this is the param value
    status: 200
    respose: >-
      {
        "id": 987,
        "message": "bar"
      }

The reason for having them defined in a list rather than as a key/value pair is due to how the (Queries](https://www.gorillatoolkit.org/pkg/mux#Route.Queries) method is defined in the router package used (gorilla mux).

Custom Response Headers

If you want the response to include a header then you can add it as such:

routes:
  - path: /foo
    status: 200
    headers:
      X-Custom: Header
      X-Request-Id: ef835eaf-a658-458b-86ae-d2d771f5e745
    respose: >-
      {
        "id": 987,
        "message": "bar"
      }

Docker

The artifact is stored as a docker image and is located on Docker Hub You can also build locally if required by running make image. Run the docker container using make run_image in this directory.

$ make run_image
# Running Docker Image Locally...
2019/02/14 17:33:37 starting server on  :8080

Or you can run the following docker run command anywhere:

docker run --rm -v "$PWD/config.yaml:/bin/config.yaml" -p 8080:8080 davyj0nes/stubby

Contributing

If you would like to contribute to this project then please check out the guidance within: CONTRIBUTING.md

License

MIT

About

HTTP server that returns stubbed responses

License:MIT License


Languages

Language:Go 67.3%Language:Makefile 24.0%Language:Dockerfile 8.8%