testinggospels / camouflage

Camouflage is a backend mocking tool for HTTP, gRPC, Websockets and Thrift protocols, which helps you carry out your front end prototyping, unit testing, functional/performance testing in silos, in absence of one or more Microservices/APIs.
https://testinggospels.github.io/camouflage/
MIT License
270 stars 26 forks source link

Enable user to write a custom code to generate a response #20

Closed shubhendumadhukar closed 3 years ago

shubhendumadhukar commented 3 years ago

Is your feature request related to a problem? Please describe. Though with handlebars, user has an extensive capability to write conditions, run loops etc without writing a code, there might be some complex use cases where the user would need to write a custom code to generate a desired response.

Describe the solution you'd like This can be implemented using a custom handlebar helper which can evaluate the code passed in via mock files and generate a desired response. Final implementation could look like following in a mock file:

HTTP/1.1 200 OK
X-Static-Header: Static-Value

{{code}}
function (request, logger) {
    var name = request.query.name;
    return {
        status: 201,
        headers: {
            "X-Dynamic-Header": "Dynamic-Value"
        },
        body: `{'greeting': 'Hello ${name}'}`
    }
}
{{/code}}

Describe alternatives you've considered NA

Additional context NA

shubhendumadhukar commented 3 years ago

Implemented and tested in development branch. Will be available for production release in camouflage-server v0.2.6