MCPcopy Index your code
hub / github.com/EIrwin/stubble

github.com/EIrwin/stubble @v1.0.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.0.0 ↗ · + Follow
19 symbols 39 edges 6 files 0 documented · 0% updated 9y agov1.0.0 · 2016-09-27★ 383 open issues
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

stubble - Mock JSON API Generator Build Status

What is stubble?

Stubble is a mock JSON API generator that uses a YAML specification to define mock API endpoints and responses.

Why stubble?

Current API response mocking solutions bloat client and/or server side code. Stubble can be ran 100% from your client and server leaving it clean and free of unecessary bloat.

Example

Stubble expects a simple YAML configuration to generate a mock JSON API.

```yaml host: "localhost"

port: "8282"

endpoints: - "GET /api/v1/users responses/users_get.json" - "POST /api/v1/users responses/users_post.json" - "PUT /api/v1/users responses/users_put.json" - "GET /api/v1/groups responses/groups_get.json" - "POST /api/v1/groups responses/groups_post.json" ```

Assuming binary is available, running the following will result in a stubble server being generated. The command assumes we have a file named sample.yaml that contains the configuration above.

./stubble -p=sample.yml

This results in the following stubble.go file to be generated.

package main

import (
    "io/ioutil"
    "log"
    "net/http"
)

func main() {
    log.Println("Running stubble server on localhost:8282")

    http.HandleFunc("/api/v1/groups", func(w http.ResponseWriter, r *http.Request) {

        if "GET" == r.Method {
            file, _ := ioutil.ReadFile("responses/groups_get.json")
            w.Header().Set("Content-Type", "application/json; charset=UTF-8")
            w.Write(file)
        }

        if "POST" == r.Method {
            file, _ := ioutil.ReadFile("responses/groups_post.json")
            w.Header().Set("Content-Type", "application/json; charset=UTF-8")
            w.Write(file)
        }

    })

    http.HandleFunc("/api/v1/users", func(w http.ResponseWriter, r *http.Request) {

        if "GET" == r.Method {
            file, _ := ioutil.ReadFile("responses/users_get.json")
            w.Header().Set("Content-Type", "application/json; charset=UTF-8")
            w.Write(file)
        }

        if "POST" == r.Method {
            file, _ := ioutil.ReadFile("responses/users_post.json")
            w.Header().Set("Content-Type", "application/json; charset=UTF-8")
            w.Write(file)
        }

        if "PUT" == r.Method {
            file, _ := ioutil.ReadFile("responses/users_put.json")
            w.Header().Set("Content-Type", "application/json; charset=UTF-8")
            w.Write(file)
        }

    })

    log.Fatal(http.ListenAndServe("localhost:8282", nil))
}

Finally, we can start our stubble server by simply running the command

go run stubble.go

Samples

To run the samples in /samples, perform the following steps

Try it out (Currently only can be done manually)

1.Clone the repository

git clone git@github.com:eirwin/stubble

2.Build and/or install

go build
go install

3.Navigate to sample directory

cd sample

4.Run stubble generator against YAML configuration

$GOPATH/bin/stubble -p=sample.yml

5.Start stubble server

go run stubble.go

6.Test out stubble

curl localhost:8282/api/v1/users

If everything was done correctly, you should see the following

curl localhost:8282/api/v1/users
{
    "users" : [
        {
            "name" : "User A"
        },
        {
            "group": "User B"
        },
        {
            "group": "User C"
        }
    ]
}

Development

Stubble uses go templates to build http handlers in Go.

Contributing

  1. Fork it ( https://github.com/eirwin/stubble/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Tasks

  1. Add Makefile
  2. Add additional content-type support.
  3. Implement HTTP response code support.
  4. Dynamic data in responses using templating.

Core symbols most depended-on inside this repo

Run
called by 1
generator/generator.go
parseEndpoints
called by 1
generator/generator.go
generateEndpointMap
called by 1
generator/generator.go
writeFile
called by 1
generator/generator.go
generator
called by 1
generator/generator.go
Parse
called by 1
endpoints/endpoint.go
removeEmptyParts
called by 1
endpoints/endpoint.go
Read
called by 1
config/config.go

Shape

Function 14
Struct 4
Method 1

Languages

Go100%

Modules by API surface

generator/generator.go8 symbols
endpoints/endpoint_test.go3 symbols
endpoints/endpoint.go3 symbols
config/config.go2 symbols
app.go2 symbols
config/config_test.go1 symbols

For agents

$ claude mcp add stubble \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page