Code Monkey home page Code Monkey logo

Comments (4)

bbyars avatar bbyars commented on May 22, 2024

I definitely like the idea. I think it's worth playing with how to represent this in the RESTful API. I didn't completely follow how the schema gets to mountebank in your example above, but given the AutoFixture-like response (AutoFixture is great, btw), it somehow needs to know how to generate the response. One idea could be as a different behavior with the schema inside the behavior definition:

{
    "port": 4545,
    "protocol": "http",
    "stubs": [
        {
            "responses": [
                {
                    "is": {
                        "statusCode": 200,
                        "body": "{\"id\": #{id}, \"name\": \"#{name}\"}"
                    },
                    "_behaviors": {
                        "generate": {
                            "id": {
                                "type": "number"
                            },
                            "name": {
                                "type": "string"
                            }
                        }
                    }
                }
            ]
        }
    ]
}

That has the advantage of working with other content types (e.g. XML) and other response fields (e.g. TCP data and HTTP statusCode) in a consistent way. If more robust generation is required (including randomly including/excluding optional fields), maybe:

{
    "port": 4545,
    "protocol": "http",
    "stubs": [
        {
            "responses": [
                {
                    "is": {
                        "statusCode": 200,
                        "body": "#{order}"
                    },
                    "_behaviors": {
                        "generate": {
                            "order": {
                                "type": "json",
                                "fields": [
                                    {
                                        "name": "id",
                                        "type": "number"
                                    },
                                    {
                                        "name": "name",
                                        "type": "string",
                                        "required": false
                                    }
                                ]
                            }
                        }
                    }
                }
            ]
        }
    ]
}

Definitely open to suggestions - did you have other ideas on how to structure the API?

from mountebank.

moodmosaic avatar moodmosaic commented on May 22, 2024

No, as far as I can tell - Stub resolvers decorated with a hypothetical new behavior sounds great :) I think create or build are probably more precise names for this particular behavior definition.

from mountebank.

bbyars avatar bbyars commented on May 22, 2024

Sounds good to me. If you're still interested in working on it, let me know if you need any help getting started. Definitely open to questions or even a skype if it helps.

from mountebank.

moodmosaic avatar moodmosaic commented on May 22, 2024

Sounds good! Thanks, I will let you know! It might take me a couple of days before I open a pull request.

from mountebank.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.