Code Monkey home page Code Monkey logo

Comments (7)

chrischenyc avatar chrischenyc commented on May 22, 2024

@bbyars so, I have some JSON files that to be included in the body response, do you have a temporary solution for this?

from mountebank.

bbyars avatar bbyars commented on May 22, 2024

Hi Chris,
Can you provide some context? Are you aiming to return the content of the
file as the JSON response? If so, then can you use the client code calling
mountebank to read the file and pass the content as the body field of the
response?
-Brandon

On Sun, Nov 9, 2014 at 7:13 PM, Chris Chen [email protected] wrote:

@bbyars https://github.com/bbyars so, I have some JSON files that to be
included in the body response, do you have a temporary solution for this?


Reply to this email directly or view it on GitHub
#27 (comment).

from mountebank.

chrischenyc avatar chrischenyc commented on May 22, 2024

@bbyars you're right. I'm currently using shell script to read JSON content from a file, and trying to "inject" the JSON data in the body response field, when I'm calling POST http://localhost:2525.

But I'm not proficient to this shell script thing, so I thought it would be nice for mountebank to allow "attach" a JSON file as part of the body response

from mountebank.

bbyars avatar bbyars commented on May 22, 2024

Got it. In that case, it sounds like setting an environment variable to
cat contents.json and interpolating that variable in the body response
field will work.

On Sun, Nov 9, 2014 at 8:33 PM, Chris Chen [email protected] wrote:

@bbyars https://github.com/bbyars you're right. I'm currently using
shell script to read JSON content from a file, and trying to "inject" the
JSON data in the body response field, when I'm calling POST
http://localhost:2525.


Reply to this email directly or view it on GitHub
#27 (comment).

from mountebank.

chrischenyc avatar chrischenyc commented on May 22, 2024

@bbyars thanks, finally got it work

schema_compact.json

{\"customer\":{\"questions\":[{\"label\":\"First Name\",\"required\":false}]}}

data_compact.json

{}

script.sh

echo $'delete all existing stubs\n'
curl --request 'DELETE' http://localhost:2525/imposters
echo $'\n'

echo $'import stubs\n'
SCHEMA_JSON=$(cat schema_compact.json)
DATA_JSON=$(cat data_compact.json)
CURL_DATA='{"port":6677,"protocol":"http","stubs":[{"responses":[{"is":{"statusCode":406}}],"predicates":[{"not":{"equals":{"headers":{"Accept":"application/json"}}}}]},{"responses":[{"is":{"statusCode":200,"headers":{"content-type":"application/json"},"body":'"$SCHEMA_JSON"'}}],"predicates":[{"equals":{"method":"GET","path":"/schema"}}]},{"responses":[{"is":{"statusCode":200,"headers":{"content-type":"application/json"},"body":"'"$DATA_JSON"'"}}],"predicates":[{"equals":{"method":"GET","path":"/data"}}]}]}'

curl -i \
--request 'POST' \
-H "Accept: application/json" \
-H "Content-Type:application/json" \
--data "$CURL_DATA" \
http://localhost:2525/imposters
echo $'\n'

from mountebank.

bbyars avatar bbyars commented on May 22, 2024

perfect - glad you got it working!

On Sun, Nov 9, 2014 at 9:23 PM, Chris Chen [email protected] wrote:

sorry, figured out, I should use:

curl -i
--request 'POST'
-H "Accept: application/json"
-H "Content-Type:application/json"
--data "$CURL_DATA" \http://localhost:2525/impostersecho $'\n'


Reply to this email directly or view it on GitHub
#27 (comment).

from mountebank.

bbyars avatar bbyars commented on May 22, 2024

would prefer this to be in client libraries to keep it portable

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.